Here is my code:
if __name__ == '__main__':
fid = open ('200502.txt')
data = fid.readlines()
data = map (string.strip, data)
x = []
y = []
da = []
for d in data:
s = d.split()
x.append(float(s[0])/10000.0)
y.append(float(s[1])/10000.0)
da.append(float(s[2]))
When I run it I got:
Traceback (most recent call last):
File "plot_data.py", line 286, in ?
x.append(float(s[0])/10000.0)
IndexError: list index out of range
The 200502.txt (840kb) file is like:
1131087 224529 3.923
1131096 224529 3.958
1131106 224530 3.897
1131116 224530 3.917
1131126 224530 3.847
(....)
This is a fragile way to load your data. My guess is it’s breaking on a newline at the end of the file, or something like that. Regardless, you should load your file with
numpy.loadtxtinstead (orcsvmodule if you don’t have access tonumpy).To get you started on that: