amazing scope?

Chris Angelico rosuav at
Fri Nov 30 17:08:45 CET 2012

On Sat, Dec 1, 2012 at 3:05 AM, andrea crotti <andrea.crotti.0 at> wrote:
> Well I knew that this works fine, even if I feel a bit guilty to do
> this, and better is:
> foo = 'bar' if some_condition else 'baz'
> Anyway for me the suprise is that something that is defined *later* at
> the module scope is found in a function which is defined *earlier*.

It's assigned to earlier. It's no different from C code like this:

int foo;

void blah()
    /* do stuff with foo */

int main()
    foo = 1;

In Python, the "int foo;" is implicit, but the scope is the same.


More information about the Python-list mailing list