Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'elif': 0.05; 'string.': 0.05; 'subject:Python': 0.06; 'differently': 0.07; 'see.': 0.07; 'answering': 0.09; 'literal': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; "'b'": 0.16; "'c'": 0.16; '23,': 0.16; "['a',": 0.16; 'complicating': 0.16; 'dict': 0.16; 'stuff.': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'resolved': 0.19; 'work,': 0.20; 'aug': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; '>': 0.26; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'evaluation': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'reply.': 0.31; 'didnt': 0.31; 'keys': 0.31; 'another': 0.32; 'url:python': 0.33; 'fri,': 0.33; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'var': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'two': 0.37; 'list': 0.37; 'skip:& 10': 0.38; 'thank': 0.38; 'question,': 0.38; 'needed': 0.38; 'pm,': 0.38; 'url:mail': 0.40; 'refer': 0.63; 'yes': 0.68; 'confusing': 0.84; 'dict()': 0.84; '2013': 0.98 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=zTEW0S9lojh9so/bqGMRS9Alcz3i5WwWko2AQtRh6Ew=; b=XVbC8AmRtHs5+hyKSMSOo9ROa8eA+vANQ65SoUXZ3PSGMcj8MlnEcYR14/dOV4QTJy BFkQm184bwA3/kD8INj2VZC7kmZ4y+wDacw/XSLZCoQmlGIyd88yr8fbI7r1Unp6uFmt 1uglVNGSup6lNPIySgPe13i1Xhjj8uZQviYxi1K9OHX5TSfL5Jh8LgIVre/mYH3Mxvh7 XHFoYBpXati9Bh5zdWeotNtDVw8kNMIqp/x/AqH9SiiVTQ5diu/Fyhl7L9wCXgXWZhWm KTZvF4S8+Zl9SN/9dNSXoP+/gKojQe1FkjmUydbSGhpyucX3MgTE3awhf0eY7C+C8G46 6U1Q== X-Received: by 10.182.113.195 with SMTP id ja3mr41313obb.46.1377342735185; Sat, 24 Aug 2013 04:12:15 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Jake Angulo Date: Sat, 24 Aug 2013 21:11:55 +1000 Subject: Re: Python variable as a string To: Neil Cerutti Content-Type: multipart/alternative; boundary=089e013d0db076fa6804e4af9865 Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 105 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377342739 news.xs4all.nl 15872 [2001:888:2000:d::a6]:58255 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52936 --089e013d0db076fa6804e4af9865 Content-Type: text/plain; charset=ISO-8859-1 Thank you all for the reply. Actually yes this was a confusing question, and borne out of trying to make a shortcut. I didnt ask to convert the contents of var into a string. All I needed was to get the literal equivalent "var" because I needed to use it in another dict object - whose keys i named the same (eg 'var') for convenience. Instead i ended up complicating stuff. I resolved this by doing things differently with (if - elif - else). Sorry for the confusion - but thanks all for answering - i can use a code or two of what you have shared! On Fri, Aug 23, 2013 at 11:23 PM, Neil Cerutti wrote: > On 2013-08-23, Jake Angulo wrote: > > I have a list *var* which after some evaluation I need to refer > > to *var* as a string. > > You must make a str version of var. > > > Pseudocode: > > > > var = ['a', 'b' , 'c' , 'd'] > > adict = dict(var='string', anothervar='anotherstring') > > anotherdict = dict() > > if : > > anotherdict[akey] = adict['var'] > > anotherdict[akey] = adict[str(var)] > > Will actually work, though you might prefer: > > anotherdict[akey] = adict[''.join(var)] > > Try them out and see. > > -- > Neil Cerutti > -- > http://mail.python.org/mailman/listinfo/python-list > --089e013d0db076fa6804e4af9865 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you all for the reply. =A0

Actual= ly yes this was a confusing question, and borne out of trying to make a sho= rtcut.
I didnt ask to convert the contents of var into a string.<= br>
All I needed was to get the literal equivalent "var" b= ecause I needed to use it in another dict object - whose keys i named the s= ame (eg 'var') for convenience. =A0Instead i ended up complicating = stuff.

I resolved this by doing things differently with (if - = elif - else).

Sorry for the confusion - but thanks= all for answering - i can use a code or two of what you have shared!



On Fri, Aug 23, 2013 at 11:23 PM, Neil Cerutti &l= t;neilc@norwich.edu<= /a>> wrote:
On 2013-08-23, Jake Angulo <jake.angulo@gmail.com> wrote:
> I have a list *var* which after some evaluation I need to refer
> to *var* as a string.

You must make a str version of var.

> Pseudocode:
>
> var =3D ['a', 'b' , 'c' , 'd']
> adict =3D dict(var=3D'string', anothervar=3D'anotherstring= ')
> anotherdict =3D dict()
> if <condition>:
> =A0 =A0 anotherdict[akey] =3D adict['var']

anotherdict[akey] =3D adict[str(var)]

Will actually work, though you might prefer:

anotherdict[akey] =3D adict[''.join(var)]

Try them out and see.

--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list

--089e013d0db076fa6804e4af9865--