What's up with rebinding assignment?

John Roth johnroth at ameritech.net
Fri Mar 21 18:28:43 EST 2003


"Ulrich Petri" <ulope at gmx.de> wrote in message
news:b5fse2$294l9f$1 at ID-67890.news.dfncis.de...
>
> "Jp Calderone" <exarkun at intarweb.us> schrieb im Newsbeitrag
> news:mailman.1048270535.12131.python-list at python.org...
> >
> >   Why is rebinding a variable from a nested scope a design flaw, if
> reading
> > it is not?
> >
> >   In my unit tests, I tend to have a lot of things like this:
> >
> > [snip unittest]
> >
> >   Why should assignment to an attribute of a name in an outer scope
be any
> > different from assignment to an actual outer name?  Or does this
code
> > have a serious design flaw? ;)
>
> Perhaps i didn't made myself very clear.
> I your case you are changing an attribute of self, not self-the-thing.
>
> What i wanted to say is that no deeper scope should be able to change
a
> higher level variable.

It depends on what you're doing. I've had cases where I actually wanted
to do that. Having to work around not being able to change variables
in the immediately enclosing scope resulted in a non-obvious mess.

Of course, that occurs very rarely. In general, that kind of side effect
is a rather noxious code smell.

John Roth
If there are things you can't do, there will be results you can't get.






More information about the Python-list mailing list