Scope

Leif K-Brooks eurleif at ecritters.biz
Fri Jun 3 22:13:49 EDT 2005


Elliot Temple wrote:
> I want to write a function, foo, so the following works:
> 
> def main():
>     n = 4
>     foo(n)
>     print n
> 
> #it prints 7

What's wrong with:

def foo(n):
    return 7

def main():
    n = 4
    n = foo(n)
    print n

Anything else (including the tricks involving mutable objects that will
no doubt be posted) will result in ugly, hard to maintain code.



More information about the Python-list mailing list