Class's metafunction problem

Jeff Epler jepler at
Fri Oct 18 13:51:05 CEST 2002

On Fri, Oct 18, 2002 at 01:24:15PM +0200, Gregor Mirai wrote:
> Is it possible that a class would have a member function, that could change
> his variables (class variables) ? Here I am not referring to instance
> variables.

class A(object):
    x = 0
    def set_x(cls, val):
	cls.x = val
    set_x = classmethod(set_x)

>>> a = A()
>>> print a.x
>>> A.set_x(37)
>>> print a.x

I think that classmethod only works with new-style classes, and only in
recent versions of python.  see the docs for more information.  see also


More information about the Python-list mailing list