Difference between these two lists?

Chris Angelico rosuav at gmail.com
Mon Jan 7 21:35:00 EST 2013


On Tue, Jan 8, 2013 at 1:21 PM,  <andydtaylor at gmail.com> wrote:
> Repr and Eval I think I get. Eval certainly. That's a familiar concept, and one I hope to use tomorrow to feed a line to psycopg2.

I hope not. Why do you need eval? It's extremely dangerous.

Chances are there's a better way to do it; if your users are entering
strings like

"['Foo', 'Bar']"

and you want them to be interpreted as lists, then you can get a much
safer function ast.literal_eval - it's equivalent to eval, but (as the
name suggests) works only with literals, so you can't call functions
etc. But even that may be overkill, depending on what you actually
need.

ChrisA



More information about the Python-list mailing list