Created
January 9, 2021 22:00
-
-
Save dimitriacosta/fb5f5569cf8b00d2ade21acf3b5ba96f to your computer and use it in GitHub Desktop.
Convert string to boolean values
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 str2bool(val): | |
"""Converts string to boolean value""" | |
if isinstance(val, bool): | |
return val | |
if val.lower() in ("yes", "y", "true", "t", "1"): | |
return True | |
if val.lower() in ("no", "n", "false", "f", "0"): | |
return False | |
raise argparse.ArgumentTypeError("Boolean value expected.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment