Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52889

Re: Python variable as a string

From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: Python variable as a string
Date 2013-08-23 13:23 +0000
Organization Norwich University
Message-ID <b7p62fFhkssU4@mid.individual.net> (permalink)
References <mailman.162.1377258034.19984.python-list@python.org>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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