Python Forum
"List index out of range" for output values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"List index out of range" for output values
#1


Hi! I'm attempting to take calculated values from a loop and output them into a text file. I currently have:
fout = open("Wishbone 1N-24HZ Output.txt", "w")
while p!=W:
    fout.write("{:f} {:f} {:f} {:f} \n".format(NewTVD[i], NewN[i], NewE[i], DLS[i]))
    p=p+1
fout.close()
W is a count of the number of values in a list that is read from an input text file.

I have the variables defined as lists and calculates values being put in:
DLS=[]
dls =...
    DLS.append(dls)
I keep getting an error of "list index out of range" and I'm not sure what that means or how to fix it. I'm using Spyder, and the DLS list does not show up in the variable explorer when I run through my loop to calculate that. I'm not sure if that is a clue to what is going wrong. I'm fairly new to coding in Python.
Reply


Messages In This Thread
"List index out of range" for output values - by pegn305 - Nov-24-2017, 09:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to remove extra space from output list? longmen 3 1,854 May-05-2022, 11:04 PM
Last Post: longmen
  How to fix list index out of range longmen 26 6,232 Apr-27-2022, 05:46 PM
Last Post: deanhystad
  list index out of range OliverG 3 2,398 Sep-03-2021, 12:04 AM
Last Post: itsmycode
  Index List a04j 2 2,961 Jul-10-2021, 01:14 PM
Last Post: BashBedlam
  List index out of range when turning CSV into dict ranbarr 15 6,596 May-12-2021, 10:38 AM
Last Post: ranbarr
  List vs index: Frederico_Caldas 5 3,670 Jul-03-2020, 10:55 AM
Last Post: DeaD_EyE
  To find the index of the first occurrence of the key in the provided list Angry_bird89 4 3,315 Jun-20-2020, 06:53 PM
Last Post: Angry_bird89
  How can I run a function inside a loop every 24 values of the loop iteration range? mcva 1 2,167 Sep-18-2019, 04:50 PM
Last Post: buran
  list index out of range mcgrim 2 2,953 May-25-2019, 07:44 PM
Last Post: mcgrim
  dictionaries and list as values Pippi 6 3,525 Apr-13-2019, 09:05 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020