Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'retrieved': 0.05; 'string.': 0.05; 'true,': 0.05; 'subject:Python': 0.06; 'string': 0.09; 'subject:string': 0.09; 'question.': 0.14; "'b'": 0.16; "'c'": 0.16; "['a',": 0.16; 'appreciated!': 0.16; 'evaluating': 0.16; 'referencing': 0.16; 'subject:variable': 0.16; 'discussion': 0.18; 'variable': 0.18; 'basically': 0.19; 'possible,': 0.19; '>>>': 0.22; 'shell': 0.22; 'to:name:python-list@python.org': 0.22; 'of.': 0.24; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'evaluation': 0.30; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'url:python': 0.33; 'actual': 0.34; 'maybe': 0.34; 'basic': 0.35; "can't": 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'var': 0.36; 'url:listinfo': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'list': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'name': 0.63; 'real': 0.63; 'refer': 0.63; 'believe,': 0.84; 'case?': 0.84; 'dict()': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=DaS0wxgXCtJy+UxLMBKDBleU2Dp83rlDsJr3DiFt1nQ=; b=uG5aqStsVike0ZsrpVgSRwD68p2FLzuwKZeeQwvstSFILyDOXEX5OL+Xek9F1qQFnK lEg/GHD5uiJn7JM7rFBLdhYVLGReXaw3YxCOhCbFTsjw4UBjWct7iJ+2TGC61mO6EFYX PA8Gwm3697lQ8LR4hzLRZZtM/6FI4nUXAZdn39UuOUZiF3Eq5XpHB6nzQ/GlaJAGo+B8 drQGn31gzCIfmShKebNcL8uC37siP21dGQ3JIanup5+KYLALcaiG3urAJVT3+dlpFEGV nYjp5/ecAYDEokZfdYA33ntEDDrP2GKFE7tvwOCw84M2J+u+XJjXE5RoSDgSw93JeT30 5apQ== MIME-Version: 1.0 X-Received: by 10.60.42.3 with SMTP id j3mr331826oel.70.1377274419035; Fri, 23 Aug 2013 09:13:39 -0700 (PDT) In-Reply-To: References: Date: Fri, 23 Aug 2013 18:13:38 +0200 Subject: Re: Python variable as a string From: Vlastimil Brom To: "python-list@python.org" Content-Type: text/plain; charset=ISO-8859-1 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: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377274427 news.xs4all.nl 15912 [2001:888:2000:d::a6]:40287 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52900 2013/8/23 Jake Angulo : > Sorry this is a very basic question. > > I have a list var which after some evaluation I need to refer to var as a > string. > > Pseudocode: > > var = ['a', 'b' , 'c' , 'd'] > adict = dict(var='string', anothervar='anotherstring') > anotherdict = dict() > if : > anotherdict[akey] = adict['var'] > > > Basically im evaluating the list var, and if true, i want to use var as a > string so that i can refer to a key-value pair in adict (whose key name is > also var for convenience). > > Or maybe i should do things differently? > > Any help and code will be appreciated! > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, if I understand correctly, you would like to achieve something like the following [fictional shell session]: >>> var = "a string variable named 'var'" >>> some_magic_function(var) 'var' >>> is it the case? I believe, it is not (easily and reliably) possible, and especially it doesn't seem to be of any real use, I can think of. cf. e.g. the discussion http://stackoverflow.com/questions/2553354/how-to-get-a-variable-name-as-a-string-in-python What is your use case, where you can't use the actual object reference, but only the string? What name string should be retrieved in case of multiple names referencing the same object? hth, vbr