On 02/24/2009 10:54 AM, [email protected] wrote: > * ** Accessing callers context from callee method** > * > > 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
This is probably a better topic for comp.lang.python or the python commuity list. Regardless... The way to do this is you climb up the calling stack and investigate the caller's locals. import sys def func(): i=10 foo() def foo(): print sys._getframe(1).f_locals['i'] func() Pretty straightforward. I do not recommend you write code like this. I certainly don't recommend you mess around with the locals so your functions can give you surprising results. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
