Binding frustration

Mel Wilson mwilson at the-wire.com
Fri Sep 19 12:43:16 EDT 2003


In article <mailman.1063925970.14284.python-list at python.org>,
Rob Hunter <rob at cs.brown.edu> wrote:
>On Thursday, September 18, 2003, at 06:21 PM, Terry Reedy wrote:
>> When, within a function, you assign to a variable that has not been
>> declared global, then you implicitly declare that variable to be local
>> to the function -- in this case, inGenre().  But local var 'result'
>> has not previously been assigned a value within inGenre.  Hence the
>> error message.  As JCM said, try result.append(g).

>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.

   Yup.  That's what Smalltalk does, but it too can be felt
to be a pain, because your first assignment to a variable
has to be different from the subsequent ones.  Breaks the
no-declarations, "just write the code" feel in Python.  Can
trip up code refactoring, as you move code around and find
that your third binding to x had just become your first.

        Regards.        Mel.




More information about the Python-list mailing list