Normally I run this script fro the command line with one argument: python myscript.py argument
But when this argument is lacking, I want the error message to be shown:
usage: myscript.py [file ...]
Script:
import sys from lxml import etree filename = sys.argv[1] tree = etree.parse(filename) def f1(): ... def main(): if len(sys.argv) < 2: print 'usage: extract.py [file ...]' sys.exit(1) else: f1() Before I had this working, I could the error message in case there is no argument, but now it stopped working, I don't see why... I only get this message when I run the script without the argument from the command line:
Traceback (most recent call last): File "myscript.py", line 14, in <module> filename = sys.argv[1] IndexError: list index out of range