[Python-ideas] eval_literal

jab at math.brown.edu jab at math.brown.edu
Mon Jun 13 18:24:03 EDT 2016


On Mon, Jun 13, 2016 at 6:16 PM, Bar Harel <bzvi7919 at gmail.com> wrote:
> That exact same thing exists mate :-)
>
> See ast.literal_eval

Cool! Perhaps I can consider it validating that I just reinvented it? :)

And to deal with the empty string case (in the absence of PEP 463), to
make it a possible substitute for some bool.from_str() method, I guess
you could do:

>>> ast.literal_eval(os.getenv('FOO', 'False'))


More information about the Python-ideas mailing list