Scope

Ron Adam rrr at ronadam.com
Sat Jun 4 18:56:01 CEST 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
> 
> if foo needs to take different arguments, that'd be alright.
> 
> Is this possible?

It is possible if you pass mutable objects to foo such as lists or 
dictionaries.

Is this what you are looking for?

def main():
     d = [3,]
     foo(d)
     print d[0]

def foo(var):
     var[0] = 7

main()


Cheers,
_Ron




More information about the Python-list mailing list