Forked from dunossauro/convert_string_types.py
Last active
February 21, 2024 18:45
-
-
Save rg3915/bfc544fe4932242ae765f182fe304310 to your computer and use it in GitHub Desktop.
Conversão de strings em tipos válidos do Python usando ast literal_eval by @dunossauro - python ast
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
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