catch empty sys.argv

pedro pedro at athlet.de
Thu Jul 12 02:58:24 EDT 2001


hi,

my scripts gets a variable from .sys.argv[1] (a filename). when the
filename is not entered the scripts is completely useless, so i
thought i'd do a basic check like:

if sys.argv[1] == ''
    exit('enter something, stupid')

but the script just fails if nothing is entered (it also fails without
the check of course):

Traceback (most recent call last):
  File "lm4l.py", line 118, in ?
    obj = argv[1]
IndexError: list index out of range

what can i do ?

thx,
pedro




More information about the Python-list mailing list