Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69116
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-03-26 04:43 -0700 |
| Message-ID | <d9daaeb5-04ef-43e8-b60e-3c4ba5790a9d@googlegroups.com> (permalink) |
| Subject | Dynamically reference member of array |
| From | Ben Collier <bmcollier@gmail.com> |
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? It's fairly academic, but I'd like to avoid code duplication. Thanks, Ben
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Dynamically reference member of array Ben Collier <bmcollier@gmail.com> - 2014-03-26 04:43 -0700
Dynamically reference variable in object Ben Collier <bmcollier@gmail.com> - 2014-03-26 04:44 -0700
Re: Dynamically reference variable in object Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-26 15:19 -0600
Re: Dynamically reference variable in object Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-26 23:42 +0000
Re: Dynamically reference member of array "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2014-03-29 22:50 -0400
csiph-web