catch empty sys.argv

pedro pedro at
Thu Jul 12 08:58:24 CEST 2001


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 "", line 118, in ?
    obj = argv[1]
IndexError: list index out of range

what can i do ?


More information about the Python-list mailing list