Is this object counter code pythonic

bruno at modulix onurb at xiludom.gro
Tue Apr 11 04:52:36 EDT 2006


jnair at ensim.com wrote:
> 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
> 

Why do you want/think you need to hide the fact that i is an attribute
of class E ?

Actually, I find this use of properties very misleading:

e1.i = 42
e2.i = 1138
assert e1.i == 42, "WTF ???"


While this is perfectly obvious:

E.i = 42



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list