Converting a list of strings into a list of integers?

Paul Rubin no.email at nospam.invalid
Sun Jul 22 19:03:07 CEST 2012


Tony the Tiger <tony at tiger.invalid> writes:
> # options.modus_list contains, e.g., "[2,3,4]"

Try this:

    import ast
    MODUS_LIST = ast.literal_eval(options.modus_list)

literal_eval is like eval except it can only evaluate literals rather
than calling functions and the like.  The idea is you can use it on
untrusted data.



More information about the Python-list mailing list