[Tutor] Accessing callers context from callee method

A.T.Hofkamp a.t.hofkamp at tue.nl
Wed Feb 25 08:21:13 CET 2009


mobiledreamers at gmail.com wrote:
> when i call a method foo from another method func. can i access func context
> variables or locals() from foo
> so
> def func():
>   i=10
>   foo()
> 
> in foo, can i access func's local variables on in this case i

As others have already pointed out, this is a really bad idea.
Instead you can do:


def func():
   i = 10
   i = foo(i)

def foo(i):
   i = i + 1
   return i

Sincerely,
Albert



More information about the Tutor mailing list