using getattr/setattr for local variables in a member function

Dave Angel davea at davea.name
Fri Nov 22 03:02:06 CET 2013


On Fri, 22 Nov 2013 00:52:21 +0000, MRAB <python at mrabarnett.plus.com> 
wrote:
> > If I have a class that has some member functions, and all the 
functions
> > define a local variable of the same name (but different type), is 
there
> > some way to use getattr/setattr to access the local variables 
specific
> > to a given function?

If you mean to access them from within the same method, someone else 
has already shown it using locals(). But you cannot access locals 
from a method that's already terminated. They no longer exist.

-- 
DaveA




More information about the Python-list mailing list