An easy way to determine if a string is valid intis to simply convert the string to intand catch an exception ValueErrorif it is not legal int. Similarly with float. Here is a quick demo in Python 2:
data = 'string 37 3.14159 word -5 0 -1.4142 text'
def datatype(s):
try:
int(s)
except ValueError:
try:
float(s)
except ValueError:
return 'string'
else:
return 'float'
else:
return 'int'
for s in data.split():
print '%-15r: %s' % (s, datatype(s))
Exit
'string' : string
'37' : int
'3.14159' : float
'word' : string
'-5' : int
'0' : int
'-1.4142' : float
'text' : string
Python () : , try: ... except ValueError:... else:, , .
CSV , , . OTOH, CSV ...:)