process the data after using str.split
Posted
by
juju
on Stack Overflow
See other posts from Stack Overflow
or by juju
Published on 2012-07-11T03:07:33Z
Indexed on
2012/07/11
3:15 UTC
Read the original article
Hit count: 110
python
|python-3.x
I parse a .txt like this:
def parse_file(src):
for line in src.readlines():
if re.search('SecId', line):
continue
else:
cols = line.split(',')
Time = cols[4]
output_file.write('{}\n'.format(
Time))
I think cols
are lists that I could use index. Although it succeeds in printing out correct result as I want, there exists an out of range error. What's the matter?
File "./tdseq.py", line 37, in parse_file
Time = cols[4]
IndexError: list index out of range
make: *** [all] Error 1
Data I use:
I10.FE,--,2008-04-16,15:15:00,13450,13488,13450,13470,490,359,16APR2008:09:15:00
I10.FE,--,2008-04-16,15:16:00,13468,13473.8,13467,13467,306,521,16APR2008:09:16:00
....
© Stack Overflow or respective owner