Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52936
| References | <mailman.162.1377258034.19984.python-list@python.org> <b7p62fFhkssU4@mid.individual.net> |
|---|---|
| From | Jake Angulo <jake.angulo@gmail.com> |
| Date | 2013-08-24 21:11 +1000 |
| Subject | Re: Python variable as a string |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.192.1377342739.19984.python-list@python.org> (permalink) |
[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