Is this function attribute weirdness a feature or bug?
Roy Katz
katz at Glue.umd.edu
Fri Aug 17 23:08:18 EDT 2001
Hello!
I am using Python 2.2a1. This works ok:
def f(): pass
f.att = 3
HOWEVER--this:
class C:
def g(): pass
C.g.att = 3
yields:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: read-only attribute: att
I get the same for instances. Now, when I attach 'f' to C, I again
get an error:
C.f = f
C.f.att2 = 3
<same exception here>
However, I can still assign attributes to global f():
f.att2 = 4
print C.f.att2 # prints '4'
So is this a design feature or a bug?
Thanks,
Roey
More information about the Python-list
mailing list