2013/8/23 Jake Angulo <jake.ang...@gmail.com>:
> Sorry this is a very basic question.
>
> I have a list var which after some evaluation I need to refer to var as a
> string.
>
> Pseudocode:
>
> var = ['a', 'b' , 'c' , 'd']
> adict = dict(var='string', anothervar='anotherstring')
> anotherdict = dict()
> if <condition>:
>     anotherdict[akey] = adict['var']
>
>
> Basically im evaluating the list var, and if true, i want to use var as a
> string so that i can refer to a key-value pair in adict (whose key name is
> also var for convenience).
>
> Or maybe i should do things differently?
>
> Any help and code will be appreciated!
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Hi,
if I understand correctly, you would like to achieve something like
the following [fictional shell session]:

>>> var = "a string variable named 'var'"
>>> some_magic_function(var)
'var'
>>>

is it the case?
I believe, it is not (easily and reliably) possible, and especially it
doesn't seem to be of any real use, I can think of.
cf. e.g. the discussion
http://stackoverflow.com/questions/2553354/how-to-get-a-variable-name-as-a-string-in-python

What is your use case, where you can't use the actual object
reference, but only the string? What name string should be retrieved
in case of multiple names referencing the same object?


hth,
   vbr
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to