using getattr/setattr for local variables in a member function

Ethan Furman ethan at stoneleaf.us
Thu Nov 21 22:18:06 EST 2013


On 11/21/2013 06:02 PM, Dave Angel wrote:
> Catherine Moroney 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.

Also, accessing is fine, but not all pythons support changing them.

--
~Ethan~



More information about the Python-list mailing list