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
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
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
"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
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
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
> 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/
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__
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
> 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
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
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):
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
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
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
15 matches
Mail list logo