Last active
January 17, 2017 10:40
-
-
Save isaaguilar/a58da1755c95641dd20d0f40c0bd10d1 to your computer and use it in GitHub Desktop.
Convert "true"/"false" url args or data params as a native Python Boolean
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 parse_true_or_false(some_array): | |
if type(some_array) == list: | |
array = enumerate(some_array) | |
else: | |
array = some_array.iteritems() | |
for key, value in array: | |
if type(value) in (dict, list): | |
parse_true_or_false(some_array[key]) | |
else: | |
try: | |
if value.lower() == 'true': | |
some_array[key] = True | |
elif value.lower() == 'false': | |
some_array[key] = False | |
except Exception as e: | |
# print str(e) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment