"Camellia" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> hi all
>
> why it generates an "UnboundLocalError" when I do the following:
>
> <code>
> ...

Presumably, the elided code includes a 'def number():' statement

> def main():
>    number = number()

Within a function, a given name can be either global or local, but not 
both.
Here you are expecting the compiler to interpret the first occurance of 
'number' as local and the second as global.  Humans can often resolve such 
ambiguities correctly, but not necessarily always.  So this is too much to 
ask of a program and hence it is not allowed.

As Benjamin said, use two different names for the two different objects 
that you need to use in the same context.

Terry Jan Reedy




-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to