# load parameters file

yml = yaml.load(open(sys.argv[1]))
# imports 

for pkg, functions in yml['imports'].iteritems():   
    stri = 'from ' + pkg + ' import ' + ','.join(functions)

for the above code i get an error

IndexError: list index out of range

in line 2..can anyone help me out ?

  • In the code listed the error should show on line 3 not on the empty line 2. Am I right? The code is also missing import sys and import yaml before the first command. Apr 27, 2015 at 8:15
  • interitems() is for Python2, you have a Python3 tag
    – Nodak
    Apr 28, 2015 at 1:37

1 Answer 1


The line:

yml = yaml.load(open(sys.argv[1]))

...assumes you pass the value, to be used in the line, as an argument when you call the script:

<script> <argument>

but probably you just ran the script without any argument.

Arguments are listed, where the command to call the script is the first item in the list (the first item is index 0).

[<script>, <sys.argv[1]>, <sys.argv[2]>]

Since you run the script with only its command (sys.argv[0]), sys.argv[1] is referring to a (list-) item that does not exist, raising an IndexError.


Not the answer you're looking for? Browse other questions tagged .