Virtual access of class attribute from within the class

Stefan Quandt squan at web.de
Tue Feb 25 23:32:53 CET 2003


> BTW, it seems that you choosen wrong design, 
> if you need something like this

Sorry, the example I gave was so much simplified that
it seems to make sense trying to do things like that.

But I found a way it works using classmethod
(instead of staticmethod):

class A( object ):
    hello = None
    def __init__( self ):
        pass
    def _setHello( Class, x  ):
        Class.hello = (x^3) * 1.2345
    setHello = classmethod( _setHello )
        
class B( A ):
    pass

A.setHello( 1 )
B.setHello( 2 )
print A.hello, B.hello




More information about the Python-list mailing list