python - How to check if an argument from commandline has been set? -
i can call script this:
python d:\myscript.py 60
and in script can do:
arg = sys.argv[1] foo(arg)
but how test if argument has been entered in command line call? need this:
if isset(sys.argv[1]): foo(sys.argv[1]) else: print "you must set argument!!!"
don't use sys.argv
handling command-line interface; there's module that: argparse
.
you can mark argument required passing required=true
add_argument
.
import argparse parser = argparse.argumentparser(description='process integers.') parser.add_argument("foo", ..., required=true) parser.parse_args()
Comments
Post a Comment