[Tutor] Index Out of Range?List

Stephen P. Molnar s.molnar at sbcglobal.net
Thu May 4 08:21:04 EDT 2017

On 05/03/2017 08:32 PM, Steven D'Aprano wrote:
> On Wed, May 03, 2017 at 07:32:53PM -0400, Stephen P. Molnar wrote:
> [...]
>> When it is run I get:
>> IndexError: list index out of range
> That alone is useless to us. Please post the full traceback, starting
> from the line
>      Traceback (most recent call last):
> Among other things, it will show us the line of code that causes the
> error. Otherwise, we're just guessing.
> You might also like to consider a simple debugging technique: print
> the index and the length of the list just before trying to use them.
> E.g. if you want to extract the nth item of a list, write:
>      print(n, len(a_list))
>      value = a_list[n]
> (And yes, I completely agree that the error message should show that
> information, but it currently doesn't.)
Thanks for the reply.

Here are the error messages:

Enter Molecule ID: A
Traceback (most recent call last):

   File "<ipython-input-1-47feaf4e6c46>", line 1, in <module>

line 866, in runfile
     execfile(filename, namespace)

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

Stephen P. Molnar, Ph.D.		Life is a fuzzy set
www.molecular-modeling.net		Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1

More information about the Tutor mailing list