Scope

Terry Reedy tjreedy at udel.edu
Sat Jun 4 02:03:05 EDT 2005


"Elliot Temple" <curi at curi.us> wrote in message 
news:0F30BFA0-4245-404E-BC14-F5D69C3D692A at curi.us...
>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?

No, you cannot *rebind* in intermediate scopes.  However you can alter.

  nl = [4]
  foo(nl(
  print nl[0] #could print anything

Or pass dict or instance

Terry J. Reedy






More information about the Python-list mailing list