given a list of python strings, how can I automatically convert them to their correct type? Meaning, if I have:
[\"hello\", \"3\", \"3.64\", \"-1\"] <
[\"hello\", \"3\", \"3.64\", \"-1\"]
def tryEval(s): try: return eval(s, {}, {}) except: return s map(tryEval, ["hello", "3", "3.64", "-1"])
Only do this if you trust the input. Also, be aware that it supports more than just literals; arithmetic expressions will be evaluated as well.