Obscure "Index out of range"


#1

Hi people :smile:
I'm working on python and, trying very simple codes, the answer is always the same: main (sys.argv[1]) Index error: list index out of range.
This is my code:

import sys
import codecs

def main (file1):
	fileInput = codecs.open(file1, "r", "utf-8")
	raw = fileInput.read()
	rawS = raw.split()
	for parola in rawS:
		print "parola:", parola.encode("utf-8")
		
main(sys.argv[1])

and the file.txt is like this:

andiamo      3         45
andare         5         47

anybody knows what is wrong with my code?

Thank you so much,
Chiara


#2

Check to see if you even have anything stored in `sys,argv' if you are passing something that has only one item or nothing in it or a nonvalid file type you will always get errors.