[Tutor] Index Out of Range?List

Alan Gauld alan.gauld at yahoo.co.uk
Thu May 4 09:44:38 EDT 2017

On 04/05/17 13:21, Stephen P. Molnar wrote:

> Here are the error messages:
> Enter Molecule ID: A
> A.lac.dat
> Traceback (most recent call last):
>    File "<ipython-input-1-47feaf4e6c46>", line 1, in <module>
>      runfile('/home/comp/Apps/Python/Testing/ReadFile_1.py', 
> wdir='/home/comp/Apps/Python/Testing')

There appears to be a missing opening paren? Or a surplus closing one?
Either way this line is not in the code you sent us. It may be coming
from your IDE - which seems to be spyder.

Can you run the code from a command prompt so we see the unpolluted
Python output. IDEs are useful but they sometimes add in extra layers
that obfuscate things.

> "/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
> line 102, in execfile
>      exec(compile(f.read(), filename, 'exec'), namespace)
>    File "/home/comp/Apps/Python/Testing/ReadFile_1.py", line 32, in <module>
>      atm_chg.append(float( line.split()[-1] ))
> IndexError: list index out of range

But it does look like it's this line that causes the error
so I'd try the check for emptiness as described in my previous post.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list