Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an argument from commandline has been set?

Tags:

python

I can call my script like this:

python D:\myscript.py 60 

And in the script I can do:

arg = sys.argv[1] foo(arg) 

But how could I test if the argument has been entered in the command line call? I need to do something like this:

if isset(sys.argv[1]):     foo(sys.argv[1]) else:     print "You must set argument!!!" 
like image 903
Richard Knop Avatar asked Nov 15 '10 20:11

Richard Knop


People also ask

Where are command line arguments stored?

All the command line arguments are stored in a character pointer array called argv[ ].

How do I see arguments in bash?

Get Values of All the Arguments in Bash We can use the $* or the $@ command to see all values given as arguments. This code prints all the values given as arguments to the screen with both commands.


1 Answers

len(sys.argv) > 1

like image 69
khachik Avatar answered Sep 25 '22 01:09

khachik