Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69365
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <michael.weylandt@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.014 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'dynamically': 0.07; 'variables': 0.07; 'collier': 0.09; 'cc:addr:python-list': 0.11; 'pythonic': 0.16; 'subject:array': 0.16; 'subject:member': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'wed,': 0.18; 'all,': 0.19; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'michael': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'object.': 0.31; "i'd": 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'ben': 0.38; 'called': 0.40; 'how': 0.40; "you're": 0.61; 'term': 0.63; 'to:addr:gmail.com': 0.65; 'mar': 0.68; '26,': 0.68 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=jjeoHDLBb6P+2mYH8ueIvMJPNpJtONpMhe0FF54Wqy4=; b=luKO5xtpymWdLWJbMMpKF94KQmxxBNWfdeEvP1NSCimEyj0J5KB9LONY6GAQPmzA/E Q5uHSDKHGXmDjZtYHoXt4EBC76Ijn07eOY2HdWGkSwY436xRKC5buoRr4YiiRxUDAU1J gf0UTK6edatey3DF5r8cka7MUyRGaBi2tBI6Nx3EaqwbG6OcTbPsNOMRmKMF8+UPpzM8 aRh9NBS2okD4fd2fOz+ztAdp4eaglFdNT+vybOzWbnE9Zqbj2RXxn2wtIkHrf4I05X/q aQosDyuQosyUuJJh2ZncLonZs3KX4fo5pYIZolLCVZjyLlql/Ns9hVzgRubYyCIzhXo0 skPg== |
| X-Received | by 10.152.235.3 with SMTP id ui3mr12561235lac.2.1396147851946; Sat, 29 Mar 2014 19:50:51 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <d9daaeb5-04ef-43e8-b60e-3c4ba5790a9d@googlegroups.com> |
| References | <d9daaeb5-04ef-43e8-b60e-3c4ba5790a9d@googlegroups.com> |
| From | "R. Michael Weylandt" <michael.weylandt@gmail.com> |
| Date | Sat, 29 Mar 2014 22:50:31 -0400 |
| Subject | Re: Dynamically reference member of array |
| To | Ben Collier <bmcollier@gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8710.1396147859.18130.python-list@python.org> (permalink) |
| Lines | 13 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1396147859 news.xs4all.nl 2829 [2001:888:2000:d::a6]:59023 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:69365 |
Show key headers only | View raw
On Wed, Mar 26, 2014 at 7:43 AM, Ben Collier <bmcollier@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
Back to comp.lang.python | Previous | Next — Previous 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