Rolling a Container Into a String

Terry Reedy tjreedy at udel.edu
Fri Jun 25 04:15:03 CEST 2004


"Kamilche" <klachemin at home.com> wrote in message
news:889cbba0.0406241742.51a2980b at posting.google.com...
> I want to convert a dict into string form, then back again. After
> discovering that eval is insecure,

With arbitrary code from an arbitrary source, yes.
If you *know* that you are eval-ing your own safe strings, then no problem.

>I wrote some code to roll a Python
> object, dict, tuple, or list into a string.

repr(object) already does that for you.  Why duplicate the work?

You only need custom a eval function, which might check that string is safe
(no function calls, no list comps) and then eval, or which might do parsing
and construction itself.

Terry J. Reedy





More information about the Python-list mailing list