Re: text color problem?
Bruce Sherwood <[email protected]>
| Newsgroups | gmane.comp.python.visualpython.user |
|---|---|
| Message-ID | <[email protected]> |
I haven't used decorators myself, and because Visual was initiated in
2000, there aren't any decorators anywhere in the Python portions of
Visual. So I'm tone-deaf to the issue here and don't understand what
advantage would accrue either to developers of Visual or users of
Visual by replacing the following code (currently found in
vis/primitives.py)
def set_color(self, color):
self.extrusion.color = color
def get_color(self):
return self.__color
color = property( get_color, set_color, None)
with
@color.setter
def set_color(self, color):
self.extrusion.color = color
@property
def get_color(self):
return self.__color
What am I missing? If I were to change this tiny piece of code to use
decorators, for consistency it would seem advisable to change all such
code segments, and I have no idea why this is advisable. Calling the
older scheme "unpythonic" doesn't help me see the light.
Bruce Sherwood
On Tue, Mar 1, 2011 at 11:11 PM, Guy K. Kloss <guy.kloss-R/[email protected]> wrote:
> 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:
>
> [email protected]
> def material(self, material):
> self.extrusion.material = material
>
> @property
> def material(self):
> return self.__material
>
> [email protected]
> 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
>
>
------------------------------------------------------------------------------
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