'classmethod' object has only read-only attributes

Thomas Guettler hv at tbz-pariv.de
Wed Nov 25 09:06:44 EST 2009


Hi,

why have classmethods only readonly attributes? It works for other methods.

exmpale code:
{{{
class Foo(object):
    @classmethod
    def bar(cls):
        pass
    bar.myattr='test'
}}}

user at host:~> python ~/tmp/t.py
Traceback (most recent call last):
  File "/home/user/tmp/t.py", line 1, in <module>
    class Foo(object):
  File "/home/user/tmp/t.py", line 5, in Foo
    bar.myattr='test'
TypeError: 'classmethod' object has only read-only attributes (assign to .myattr)


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de



More information about the Python-list mailing list