Binding frustration

Ulrich Petri ulope at gmx.de
Fri Sep 19 08:23:25 EDT 2003


"Rob Hunter" <rob at cs.brown.edu> schrieb im Newsbeitrag
news:mailman.1063925970.14284.python-list at python.org...
>
> So it seems that if Python made a syntactic distinction between
> introducing a new binding, and assigning to an old one, then this
> problem would go away.  That's what is happening with result.append(g),
> right?  Because of the syntax in this statement (ie, there's no "=" in
> it), Python knows that _result_ must exist, so it goes and looks for
> it.  But, IMO, I *should* be allowed to use the + (append) operator.
> Because there is no syntax for a new binding (like LET, for example),
> Python awkwardly forces the programmer to choose either the local scope
> or the global one when it comes to assignment.  And so, in my case, it
> forces me to use another (but semantically, quite similar) language
> construct.
>

What result.append(bla) does is not an "assignement to an old binding". It
mutates the object that is bound to the name "result". In order to do so
Python looks up the name in the local namespace if it isn't found there it
looks in the namespace above and so on.

Whenever you use the assignment syntax (foo = bar) you create a "new"
binding unless you have declared the name global.

HTH

Ciao Ulrich






More information about the Python-list mailing list