Dumb newbie back in shell

Peter Otten __peter__ at web.de
Mon Dec 10 12:13:40 EST 2007


MartinRinehart wrote:

> However, here's the little tester I wrote:
> 
> # t.py - testing
> 
> global g
> g = 'global var, here'
> 
> def f():
>     print g
> 
> f()
> 
> It prints 'global var, here,' not an error message. Wassup?

Try it again with a modified f():

def f():
    print g
    g = 42

In Python variables that are assigned to in a function are
function-local by default.

Peter



More information about the Python-list mailing list