If a Python string variable has had either an integer, floating point number or a non-numeric string placed in it, is there a way to easily test the "type" of that value?
The code below is real (and correct of course):
>>> strVar = "145"
>>> print type(strVar)
>>> print typeofvalue(strVar)
>>> print type(unquote(strVar))
import ast def type_of_value(var): try: return type(ast.literal_eval(var)) except Exception: return str
Or, if you only want to check for int, change the third line to block inside
int(var) return int