Python variable as a string
Neil Cerutti
neilc at norwich.edu
Fri Aug 23 09:23:27 EDT 2013
On 2013-08-23, Jake Angulo <jake.angulo at 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
More information about the Python-list
mailing list