Python 3000 idea: reversing the order of chained assignments
Alex Martelli
aleax at mac.com
Wed Mar 21 22:06:56 EDT 2007
John Nagle <nagle at animats.com> wrote:
> Marcin Ciura wrote:
>
> > Neither would I. I must have expressed myself not clearly enough.
> > Currently
> > x = y = z
> > is roughly equivalent to
> > x = z
> > y = z
> > I propose to change it to
> > y = z
> > x = z
>
> Actually, it is equivalent to
>
> y = z
> x = y
Not really:
>>> class chatty(object):
... def __init__(self): self.__dict__['__hide'] = {}
... def __setattr__(self, name, value):
... print 'sa', name, value
... self.__dict__['__hide'][name] = value
... def __getattr__(self, name):
... print 'ga', name
... return self.__dict__['__hide'].get(name)
...
>>> c = chatty()
>>> x = c.zop = 23
sa zop 23
>>>
As you can see, there is no read-access to c.zop, which plays the role
of y there.
Alex
More information about the Python-list
mailing list