From: Chris Rebert on 9 May 2010 05:01
On Sun, May 9, 2010 at 1:33 AM, gopi krishna <dasarathulagopi(a)gmail.com> wrote:
> My Question is
> can we access the variables defined in a function ?
>>>> class A:
> Â Â def b(self):
> Â Â Â Â x=40
> Â Â z=40
> We can access the variables defined in a class as shown above Â in the same
> way can we access the variables defined in a method?
There is likely a very hackish way to do it involving bytecode
disassembly, but it's ill-advised. Further, what if the variable isn't
a constant, as `y` is in the following example?:
Â Â def foo(self, x):
Â Â Â Â y = x + 3
What would you expect to get for y's value?
Why would you want such an ability in the first place? I suspect that
if you explained your use-case/situation, someone could offer a much
better alternative approach.