Re: Object default value

2005-09-22 Thread Reinhold Birkenfeld
ago wrote: > Is it possible to have a default value associated python objects? I.e. > to flag an attribute in such a way that the assignment operator for the > object returns the default attribute instead of the object itself, but > calls to other object attributes are properly resolved? (I don't t

Re: Object default value

2005-09-22 Thread Bengt Richter
On 20 Sep 2005 12:31:19 -0700, "ago" <[EMAIL PROTECTED]> wrote: >Is it possible to have a default value associated python objects? I.e. >to flag an attribute in such a way that the assignment operator for the >object returns the default attribute instead of the object itself, but >calls to other o

Re: Object default value

2005-09-21 Thread James Stroud
On Tuesday 20 September 2005 12:31, ago wrote: > Is it possible to have a default value associated python objects? I.e. > to flag an attribute in such a way that the assignment operator for the > object returns the default attribute instead of the object itself, but > calls to other object attribut

Re: Object default value

2005-09-21 Thread Fredrik Lundh
"ago" <[EMAIL PROTECTED]> wrote: > Is it possible to have a default value associated python objects? I.e. > to flag an attribute in such a way that the assignment operator for the > object returns the default attribute instead of the object itself, but > calls to other object attributes are proper

Re: Object default value

2005-09-20 Thread Scott David Daniels
James Stroud wrote: > I think you want to overload the assignment operator here. I'm not sure that > is allowed in python (I've never seen it done) > But I don't think assignment overloading is allowed in python: Exactly correct. Assignment is an operation on a namespace using a new value, a

Re: Object default value

2005-09-20 Thread ago
In fact even IF I could get a default value to work as mentioned, then I would be creating potential name conflicts between the DataAttribute.DefaultValue and the other metadata. I.e. when calling obj.attr.x I could refer to DataAttribute.x or DataAttribute.value.x. It's a no go. -- http://mail.p

Re: Object default value

2005-09-20 Thread ago
> Is it safe to assume that the OP's next question will be how to invoke functions without the ()'s? To save you the trouble, then answer is 'no'. You probably nailed it, thanks for the answer. I suspected that was the case. I think I'll use __call__ + __set__ -- http://mail.python.org/mailman/

Re: Object default value

2005-09-20 Thread ago
I am trying to write a generic DataAttribute class in order to simplify access to object attributes and attached attribute-metadata for end users with little programming experience. Requirement 1: accessing the "default" value should be easy (using assignment operator, via descriptors like __get__

Re: Object default value

2005-09-20 Thread Diez B. Roggisch
ago wrote: > Is it possible to have a default value associated python objects? I.e. > to flag an attribute in such a way that the assignment operator for the > object returns the default attribute instead of the object itself, but > calls to other object attributes are properly resolved? (I don't t

Re: Object default value

2005-09-20 Thread Paul McGuire
> I think you want to overload the assignment operator here. I'm not sure that > is allowed in python (I've never seen it done). You can't because assignment is not an operator in Python. Is it safe to assume that the OP's next question will be how to invoke functions without the ()'s? To save y

Re: Object default value

2005-09-20 Thread James Stroud
See this recent clpy thread: http://www.thescripts.com/forum/thread19253.html On Tuesday 20 September 2005 13:05, ago wrote: > The print statement was only for illustrative purposes, when calling > varx=myobj I need to receive obj.x as opposed to the instance of obj, > but I also need to call var

Re: Object default value

2005-09-20 Thread James Stroud
I think you want to overload the assignment operator here. I'm not sure that is allowed in python (I've never seen it done). You can overload the equality, lt, gt, le, ge operators (==, <, ...) such that class Thing: x = 5 def __str__(self): return str(self.x) def __eq__(self, other):

Re: Object default value

2005-09-20 Thread ago
The print statement was only for illustrative purposes, when calling varx=myobj I need to receive obj.x as opposed to the instance of obj, but I also need to call vary=myobj.y. Something like that exists for com objects/VB, for instance an excel range object uses value as the default attribute, so

Re: Object default value

2005-09-20 Thread Larry Bates
The prints can be done by defining an __str__ method on the class, but I don't think you will get the type(obj) to work the way you want. class obj(object): __default=1 y=2 def __str__(self): return str(self.__default) myobj=obj() print "myobj=", myobj print "myobj.y=", myobj

Object default value

2005-09-20 Thread ago
Is it possible to have a default value associated python objects? I.e. to flag an attribute in such a way that the assignment operator for the object returns the default attribute instead of the object itself, but calls to other object attributes are properly resolved? (I don't think so, but I am n