I need some way to reliably identify whether a string can be of another type eg. "1" would evaluate to 1 – an int, "2.0" would evaluate to 2.0 – a float and "John has 3 apples" would just evaluate to a string. Is there some package that does this – builtin or otherwise?
It would be great if it also worked on dates and currency
>Solution :
You can do this with ast.literal_eval
int_type = ast.literal_eval("1")
float_type = ast.literal_eval("2.0")
But will only work on python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, None and Ellipsis