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: 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: References: From: "R. Michael Weylandt" Date: Sat, 29 Mar 2014 22:50:31 -0400 Subject: Re: Dynamically reference member of array To: Ben Collier Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, Mar 26, 2014 at 7:43 AM, Ben Collier 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