Beginner problem.
Mark McEahern
marklists at mceahern.com
Mon Feb 11 07:25:22 EST 2002
[DelPiccolo Ivano]
> How can i know if i have parameters in the command line.
>
> Here's my script, where is the error ?
>
> import sys
>
> if sys.argv[??????] == "" :
> print "Usage : sys.argv[0] logname string_to_search"
> else :
> ...........
> ..........
> ..........
This tells you how many arguments you have:
len(sys.argv)
Here's a sample that should get you started:
#! /usr/bin/env python
# junk.py
import sys
path = sys.argv[0]
if len(sys.argv) == 1:
print "No arguments were specified for %s." % path
else:
for arg in sys.argv:
print arg
Running it...
$ junk.py
No arguments were specified for ./junk.py.
$ junk.py foo bar
./junk.py
foo
bar
Cheers,
// mark
More information about the Python-list
mailing list