Skip to content

Instantly share code, notes, and snippets.

@rg3915
Forked from dunossauro/convert_string_types.py
Last active February 21, 2024 18:45
Show Gist options
  • Save rg3915/bfc544fe4932242ae765f182fe304310 to your computer and use it in GitHub Desktop.
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
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