Maximum List size (item number) limit?
Juho Schultz
juho.schultz at helsinki.fi
Wed Jan 11 07:56:11 EST 2006
Kriston-Vizi Janos wrote:
> Dear Mr. Kern, and Members,
>
> Thank you very much for the fast answer, my question became
> over-simplified.
>
> My source code is appended below. It uses two text files (L.txt and
> GC.txt) as input and merges them.
>
> Both L.txt and GC.txt contains 3000 rows. When running, the code stops
> with error message:
>
> 'The debugged program raised the exception IndexError "list index out of
> range"
> File: /home/kvjanos/file.py, Line: 91'
>
> And I noticed that all the lists that should contain 3000 items,
> contains less as follows:
> NIR_mean_l = 1000 items
> Code that's failing:
> # Processing L file
> line_no_l =0 # Input L file line number
> type_l = 1 # Input L file row type: 1 (row n),2 (row n+1) or 3 (row n+2)
> # Append L values to lists.
> for line in inp_file_l.xreadlines():
> line_no_l = line_no_l + 1
> if line_no_l == 1: # To skip the header row
> continue
> data_l = [] # An L row
> data_l = line.split()
> if type_l == 1:
> NIR_mean_l.append(data_l[2]) # Append 3rd item of the row to the list
> NIR_stdev_l.append(data_l[3]) # Append 4th item of the row to the list
> type_l = 2 # Change to row n+1
> else:
> if type_l == 2:
> R_mean_l.append(data_l[2])
> R_stdev_l.append(data_l[3])
> type_l = 3
> else:
> G_mean_l.append(data_l[2])
> G_stdev_l.append(data_l[3])
> area_l.append(data_l[1])
> type_l = 1
> inp_file_l.close()
>
Looking at the data files, it seems there is no header row to skip.
Skipping 1st row seems to cause the discrepancy of vector sizes,
which leads to the IndexError. should NIR_mean_l[0] be 203 or 25?
As the comments in your code suggest, the code adds values to
NIR_mean_l only from lines 1, 4, 7, ...
R_mean_l only from lines 2, 5, 8, ...
G_mean_l only from lines 3, 6, 9, ...
Try with 12 lines of input data and see how the vectors
are 4 elements before filtering/writing.
More information about the Python-list
mailing list