Skip to content

Instantly share code, notes, and snippets.

@KrisYu
Created November 17, 2021 20:19
Show Gist options
  • Save KrisYu/e7944d16b4bc99a88f6224e342c1eca2 to your computer and use it in GitHub Desktop.
Save KrisYu/e7944d16b4bc99a88f6224e342c1eca2 to your computer and use it in GitHub Desktop.
command line parse
# https://stackoverflow.com/questions/15753701/how-can-i-pass-a-list-as-a-command-line-argument-with-argparse
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input',type = str, default = "sample.json")
parser.add_argument( "-l","--list", nargs="*", type=int, default=[0,1,2])
args = parser.parse_args()
print("filename: ", args.input)
print("list:", args.list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment