In Python, how can I parse a numeric string like \"545.2222\" to its corresponding float value, 545.2222? Or parse the string \"31\" t
\"545.2222\"
545.2222
\"31\"
I use this function for that
import ast def parse_str(s): try: return ast.literal_eval(str(s)) except: return
It will convert the string to its type
value = parse_str('1') # Returns Integer value = parse_str('1.5') # Returns Float