Dynamically reference member of array

R. Michael Weylandt michael.weylandt at gmail.com
Sat Mar 29 22:50:31 EDT 2014


On Wed, Mar 26, 2014 at 7:43 AM, Ben Collier <bmcollier at gmail.com> wrote:
> Hi all,
>
> I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object.
>
> If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these?
>

I think the pythonic term you're looking for is "attribute". See
getattr() and setattr()

Cheers,
Michael



More information about the Python-list mailing list