newbie question

Steve Holden sholden at holdenweb.com
Wed Feb 7 22:03:02 EST 2001


"Denis Laroche" <dlaroche at dsuper.net> wrote in message
news:3A820E6B.CB29AFBC at dsuper.net...
> Hello Python enthusiasts,
>
> I just started to learn the language this week.
>
Good stuff.

> Could someone tell me how to recreate a list or a dictionary object from
> its string representation obtained with repr().
>
> Thanks in advance for any help.
>

Just use the eval() built-in:

>>> d = {1:"one", 'two':2}
>>> s = repr(d)
>>> print s
{'two': 2, 1: 'one'}
>>> d1 = eval(s)
>>> d1
{'two': 2, 1: 'one'}
>>>
regards
 Steve
--
Tools, training and technology to help you meet your information needs








More information about the Python-list mailing list