[Python-bugs-list] [ python-Bugs-615131 ] No attributes in nested functions
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 26 Sep 2002 12:27:47 -0700
Bugs item #615131, was opened at 2002-09-26 14:58
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=615131&group_id=5470
Category: None
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Jesús Cea Avión (jcea)
Assigned to: Guido van Rossum (gvanrossum)
Summary: No attributes in nested functions
Initial Comment:
Python 2.2.1
I need this feature to keep a singleton inside and
local to a particular class method, for example.
This works fine:
>>> def a() :
... pass
...
>>> a.abc=23
>>> print a
<function a at 0x141500>
>>> print a.abc
23
>>>
This DOESN'T WORK:
>>> class a :
... def perico(self) :
... pass
...
>>> b=a()
>>> b.perico.abc=23
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'instance method' object has no
attribute 'abc'
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-09-26 15:27
Message:
Logged In: YES
user_id=6380
Not a bug. You're not allowed to set attributes on (bound or
unbound) methods, only on functions.
You can do this by writing a.__dict__['perico'].abc = 23.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=615131&group_id=5470