Python: argv and IndexError
Question: I am trying to reproduce the results of a research article which they provided
the python codes. There is a script to download their data and I am trying to
run the script from terminal by,

> python getData.py

an it raises the error

> File "getData.py", line 127, in dataFile = sys.argv[1]+"/raw-comp.txt"
> IndexError: list index out of range

Related part in the python code is here,

    
    
    if __name__ == '__main__' :
    
        dataFile = sys.argv[1]+"/raw-comp.txt"
        # Read the data
    

I don't know if it is related or not; but 'getData.py' script is under 'src'
folder whereas 'raw-comp.txt' file is under 'data' folder.

I check out this solution here, [python : IndexError: list index out of
range](http://stackoverflow.com/questions/18509289/python-indexerror-list-
index-out-of-range) and it says `argv` stores the command line arguments and
you need to pass the arguments before calling it. I also checked this out;
[from sys import argv - what is the function of
"script"](http://stackoverflow.com/questions/13666346/from-sys-import-argv-
what-is-the-function-of-script) where script and filename were assigned to
argv. But here in this code, argv was not defined before the code piece above,
besides it is the first time argv is seen in the script.

I really have no idea why it did not run, because it supposed to work without
any modifying they say. Thanks already.

**Edit:** They have provided the description below for the script, they do not
mention any argument that has to be passed from terminal.

    
    
    getData: a script to download and/or build the data files.
    


Answer: Try running it as:

    
    
    python getData.py ../data
    

The presence of `sys.argv[1]` means the program cannot be run without passing
at least one command line argument.

As documented in the [python
documentation](http://docs.python.org/2/library/sys.html) `sys.argv` is a list
of command line arguments with the first entry `sys.argv[0]` being the script
name. The `ÌndexError` exception occurs when no command line arguments are
passed as the code is trying to access a none existent entry.

