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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -