Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60190

Re: using getattr/setattr for local variables in a member function

From Dave Angel <davea@davea.name>
Subject Re: using getattr/setattr for local variables in a member function
Date 2013-11-21 21:02 -0500
References <l6m40a$9vd$1@news.jpl.nasa.gov> <528EAAC5.7070402@mrabarnett.plus.com>
Newsgroups comp.lang.python
Message-ID <mailman.3023.1385085707.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, 22 Nov 2013 00:52:21 +0000, MRAB <python@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

using getattr/setattr for local variables in a member function Catherine M Moroney <Catherine.M.Moroney@jpl.nasa.gov> - 2013-11-21 15:12 -0800
  Re: using getattr/setattr for local variables in a member function MRAB <python@mrabarnett.plus.com> - 2013-11-22 00:52 +0000
  Re: using getattr/setattr for local variables in a member function Ned Batchelder <ned@nedbatchelder.com> - 2013-11-21 17:58 -0800
  Re: using getattr/setattr for local variables in a member function Dave Angel <davea@davea.name> - 2013-11-21 21:02 -0500
  Re: using getattr/setattr for local variables in a member function Ethan Furman <ethan@stoneleaf.us> - 2013-11-21 19:18 -0800
  Re: using getattr/setattr for local variables in a member function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-11-22 17:07 +1300

csiph-web