My problem is different because it does not deal with regular expressions. so I think its a slightly different. I got this error.
ValueError: invalid literal for float(): 512220 0 20 34.4
2.4 0 10010 913 52 0.00
my csv file looks like
512220 0 20 34.4 2.4 0 10010 913 52 0.00
512221 1 30 34.6 2.3 0 10230 910.3 54 0.00
512222 2 50 34.8 2.1 0 10020 932 56 0.00
512223 3 60 35.4 2.5 0 10340 945.5 58 0.00
my code is
with open(item[1]) as f:
lines = f.readlines()
print 'lines', lines
for k, line in enumerate(lines):
data_temporary = line.strip().split("\r\n")
when i print "lines" i got follwing
['512220 0 20 34.4 2.4 0 10010 913 52
0.00\n', '512221 1 30 34.6 2.3 0 10230 910.3
54 0.00\n', '512222 2 50 34.8 2.1 0 10020
932 56 0.00\n', '512223 3 60 35.4 2.5
0 10340 945.5 58 0.00'\n]
when I print data_temporary i got the following one line only.
['160129 29 0000 0 0.04 5.3 2.04
0.00 11758 9.13 52 0.00']
I tried these commands and results are as follows. . data_temporary = line.strip().split(" ")
['512220', '', '', '', '', '', '', '0', '', '', '', '', '', '20', '', '', '',
'', '', '', '34.4', '', '', '', '', '', '2.4', '', '', '', '', '', '0', '', '',
'', '10010', '', '', '', '', '', '913', '', '','', '', '', '52', '', '',
'', '', '', '0.00']
I tried to apply different solutions found on SO but couldn't work. like I try to use
lines = map(lambda l: l.strip().split('\t'), lines) and some others.
I think I had to break list into string and then perform operation on it. could someone help me to solve this problem so that I understand better. thanks