Skip to content

Instantly share code, notes, and snippets.

@ucaiado
Created January 26, 2015 19:33
Show Gist options
  • Select an option

  • Save ucaiado/50a157cc5411866e682c to your computer and use it in GitHub Desktop.

Select an option

Save ucaiado/50a157cc5411866e682c to your computer and use it in GitHub Desktop.
Check numers in Python
def isfloat(x):
try:
a = float(x)
except ValueError:
return False
else:
return True
def isint(x):
try:
a = float(x)
b = int(a)
except ValueError:
return False
else:
return a == b
def check_type(s):
"""Check the type of a string passed"""
#define the possible types
o_str, o_int = type('a'),type(1)
o_float, o_list, o_null=type(1.1), type([]), type(None)
if s[0]=="{": return o_list
elif (s=='NULL') | (s==""): return o_null
elif isfloat(s) : return o_float
elif isint(s) : return o_int
else: return o_str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment