Re: reuse validation logic with descriptors

2005-03-02 Thread David S.
Steve Holden holdenweb.com> writes: > You want assignment to a method-local variable to turn an attribute into > a property? That's programming with a magic wand ... > > That will depend on the value returned by property access, surely? > > I suspect you are a little confused about propertie

Re: reuse validation logic with descriptors

2005-03-02 Thread Nick Coghlan
David S. wrote: Steve, and others, thanks for the help. This and Michael Spencer's reply at http://article.gmane.org/gmane.comp.python.general/390478 have been very helpful in getting the descriptor definition clear. For me, it has taken reading http://users.rcn.com/python/download/Descriptor.ht

Re: reuse validation logic with descriptors

2005-03-01 Thread Steve Holden
David S. wrote: Steven Bethard gmail.com> writes: David S. wrote: I am looking for a way to implement the same simple validation on many instance attributes and I thought descriptors (http://users.rcn.com/python/download/Descriptor.htm) looked like the right tool. Looks like you're trying to

Re: reuse validation logic with descriptors

2005-03-01 Thread David S.
Steven Bethard gmail.com> writes: > > P.S. If you haven't already, you should read > http://users.rcn.com/python/download/Descriptor.htm a couple of times. > It took me until about the third time I read it to really understand > what descriptors were doing. The big thing to remember is that

Re: reuse validation logic with descriptors

2005-03-01 Thread Steven Bethard
David S. wrote: Steven Bethard gmail.com> writes: Looks like you're trying to reinvent the property descriptor. Try using the builtin property instead: py> def getchar(self): ... if not hasattr(self, '_char'): ... self._char = None ... return self._char ... py> def setchar(self,

Re: reuse validation logic with descriptors

2005-03-01 Thread Michael Spencer
David S. wrote: This still fails to work for instances variables of the class. That is if I use your property in the following: py> ...class Flags(object): ...def __init__(self): ... a = singlechar ... you should write that as: class Flags(object): a = singlechar def

Re: reuse validation logic with descriptors

2005-03-01 Thread David S.
Steven Bethard gmail.com> writes: > > David S. wrote: > > I am looking for a way to implement the same simple validation on many > > instance attributes and I thought descriptors > > (http://users.rcn.com/python/download/Descriptor.htm) looked like the > > right tool. > > > Looks like you'r

Re: reuse validation logic with descriptors

2005-03-01 Thread Steven Bethard
David S. wrote: I am looking for a way to implement the same simple validation on many instance attributes and I thought descriptors (http://users.rcn.com/python/download/Descriptor.htm) looked like the right tool. But I am confused by their behavior on instance of my class. I can only get th

reuse validation logic with descriptors

2005-03-01 Thread David S.
I am looking for a way to implement the same simple validation on many instance attributes and I thought descriptors (http://users.rcn.com/python/download/Descriptor.htm) looked like the right tool. But I am confused by their behavior on instance of my class. I can only get the approximate be