Re: text color problem?

"Guy K. Kloss" <guy.kloss-R/[email protected]>
Newsgroups gmane.comp.python.visualpython.user
Organization School of Computing + Mathematical Sciences
Message-ID <[email protected]>
On Wed, 02 Mar 2011 06:45:04 Bruce Sherwood wrote:
> In vis/primitives.py, the code for
> changing color and material for a text object should look like this:
> 
>     def set_material(self, material):
>         self.extrusion.material = material
>     def get_material(self):
>         return self.__material
> 
>     def set_color(self, color):
>         self.extrusion.color = color
>     def get_color(self):
>         return self.__color

Are you *really* sure about that? Python usually does not use the concept of 
getters and setters. This turns out to be *very* unpythonic. I'd rather 
suggest the following:

    @material.setter
    def material(self, material):
        self.extrusion.material = material

    @property
    def material(self):
        return self.__material

    @color.setter
    def set_color(self, color):
        self.extrusion.color = color

    @property
    def get_color(self):
        return self.__color

This exposes the given methods to transparently handle access (setting and 
getting) to mock attributes as they would be normally used within Python 
classes. It makes a nice API that is idiomatically consistent to use for a 
Pythoneer.

For further reference on how to use the property() built-in, particularly in 
the way of decorators, have a look here:

http://docs.python.org/library/functions.html#property

Guy

-- 
Guy K. Kloss
School of Computing + Mathematical Sciences
Auckland University of Technology
Private Bag 92006, Auckland 1142
phone: +64 9 921 9999 ext. 5032
eMail: Guy.Kloss-R/[email protected]

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev

_______________________________________________
Visualpython-users mailing list
Visualpython-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/visualpython-users
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEABECAAYFAk1t35EACgkQpsb+VXwam+S83gCeMuG1M5AtG8plXodUMNjs4q6j
tiwAn0t7NObyQc+bcugkfWC7UxxPU40h
=mAhy
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.