Created
May 4, 2016 06:41
-
-
Save krid78/066a7509244b3ea59cf0cc2825df38c4 to your computer and use it in GitHub Desktop.
return correct type for value in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def type_set(val): | |
""" | |
return the value with its correct type | |
default type of return value is str | |
:val: input value of any type | |
:return: same value, correct type | |
""" | |
try: | |
return int(val) | |
except ValueError: | |
pass | |
try: | |
return float(val) | |
except ValueError: | |
pass | |
return str(val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment