Background:
I mostly run python scripts from the command line in pipelines and so my arguments are always strings that need to be type casted to the app
If you want to auto-convert values:
def boolify(s):
if s == 'True':
return True
if s == 'False':
return False
raise ValueError("huh?")
def autoconvert(s):
for fn in (boolify, int, float):
try:
return fn(s)
except ValueError:
pass
return s
You can adjust boolify
to accept other boolean values if you like.