Ethan Furman a écrit :
Bruno Desthuilliers wrote:
Duncan Booth a écrit :
(snip)

Or you could create the default as a class attribute

from the OP:
"""
I have a class (FuncDesigner oofun) that has no attribute "size", but
it is overloaded in __getattr__, so if someone invokes
"myObject.size", it is generated (as another oofun) and connected to
myObject as attribute.
"""

so this solution won't obviously work in this case !-)

Also and FWIW, I wouldn't advocate this solution if the "default" class attribute is of a mutable type.

Well, it is Monday, so I may be missing something obvious, but what is the effective difference between these two solutions?


Now it's Tuesday !-)


Ok, let's see:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
...     whatever = Foo()
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in Foo
NameError: name 'Foo' is not defined
>>>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to