Skip to content

Instantly share code, notes, and snippets.

@saber-zero
Created May 24, 2019 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saber-zero/62fb1403a1752bb8d190aa25362cc91b to your computer and use it in GitHub Desktop.
Save saber-zero/62fb1403a1752bb8d190aa25362cc91b to your computer and use it in GitHub Desktop.
def str2bool(v):
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
parser = argparse.ArgumentParser()
parser.add_argument("--True_or_False", type=str2bool, nargs='?',
const=True, default=True,
help="Activate nice mode.")
opt = parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment