Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52936
| 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 | <jake.angulo@gmail.com> |
| 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 | <b7p62fFhkssU4@mid.individual.net> |
| References | <mailman.162.1377258034.19984.python-list@python.org> <b7p62fFhkssU4@mid.individual.net> |
| From | Jake Angulo <jake.angulo@gmail.com> |
| Date | Sat, 24 Aug 2013 21:11:55 +1000 |
| Subject | Re: Python variable as a string |
| To | Neil Cerutti <neilc@norwich.edu> |
| Content-Type | multipart/alternative; boundary=089e013d0db076fa6804e4af9865 |
| Cc | "python-list@python.org" <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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.192.1377342739.19984.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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 <neilc@norwich.edu> 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 = ['a', 'b' , 'c' , 'd'] > > adict = dict(var='string', anothervar='anotherstring') > > anotherdict = dict() > > if <condition>: > > 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 >
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python variable as a string Jake Angulo <jake.angulo@gmail.com> - 2013-08-23 21:40 +1000
Re: Python variable as a string Neil Cerutti <neilc@norwich.edu> - 2013-08-23 13:23 +0000
Re: Python variable as a string Jake Angulo <jake.angulo@gmail.com> - 2013-08-24 21:11 +1000
Re: Python variable as a string Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-23 13:40 +0000
csiph-web