Is this object counter code pythonic

jnair at ensim.com jnair at ensim.com
Mon Apr 10 08:00:51 EDT 2006


Fredrik is then this a valid "property"  use  case and pythonic  to
get/set a common varibale  across objects

class E(object):
    _i = 0
    def geti(self) : return E._i
    def seti(self,val) : E._i = val
    i = property(geti,seti)

if __name__ == "__main__":
    e1 = E()
    e1.i = 100    
    e2 = E()
    print e2.i




More information about the Python-list mailing list