getting values from a text file (newby)

vsoler vicente.soler at gmail.com
Sun Feb 1 12:24:37 EST 2009


Hi,

My foo.txt file contains the following:

1,"house","2,5"
2,"table","6,7"
3,"chair","-4,5"

... as seen with notepad.

This file was created with the OpenOffice Calc spreadsheet, but since
I use comma as the decimal separator for numbers, the last value in
each line appears sorrounded by quotes.

I would like to obtain:

[[1,"house",2.5], [2,"table",6.7], [3,"chair",-4.5]]

in order to process the content of the file. However, so far, I have
not obtained the desired result.

I started testing with (only for first line):

f=open('foo.txt','r')
t=f.readline()
print t
t=t.split(',')
print t
f.close()

But what I am getting is far more complex than what I expected:

1,"house","2,5"

['1', '"house"', '"2', '5"\n']

which is unprocessable.

Can anyboby help?



More information about the Python-list mailing list