Last active
December 14, 2018 18:21
-
-
Save dunossauro/5918e69beb43640686aaad56c240ed29 to your computer and use it in GitHub Desktop.
Conversão de strings em tipos válidos do python usando literal_eval
This file contains 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
from ast import literal_eval | |
def convert_to_type(input_data): | |
try: | |
return literal_eval(input_data) | |
except (ValueError, SyntaxError): | |
return input_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment