Class Variable Access and Assignment

Mike Meyer mwm at mired.org
Fri Nov 4 05:22:06 EST 2005


> Would it be too much to ask that in a line like.
> 
>   x = x + 1.
> 
> both x's would resolve to the same namespace?

Yes. That's to much bondage for programmers who've become accustomed
to freedom. Explain why this should be illegal:

>>> class C:
...  def __getattr__(self, name):
...   x = 1
...   return locals()[name]
...  def __setattr__(self, name, value):
...   globals()[name] = value
... 
>>> o = C()
>>> o.x = o.x + 1
>>> x
2
>>> 


    <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list