Re: getting values from a text file (newby)

2009-02-01 Thread John Machin
On Feb 2, 10:18 am, vsoler wrote: > On 1 feb, 23:57, John Machin wrote: > > > On Feb 2, 6:18 am, vsoler wrote: > > > > r: in the open statement, why do you use 'rb' as 2nd argument? b is > > > supposed to be binary, and my file is text! > > > Because unlike Stephen, r has read the csv manual. Bi

Re: getting values from a text file (newby)

2009-02-01 Thread vsoler
On 1 feb, 23:57, John Machin wrote: > On Feb 2, 6:18 am, vsoler wrote: > > > > > r: in the open statement, why do you use 'rb' as 2nd argument? b is > > supposed to be binary, and my file is text! > > Because unlike Stephen, r has read the csv manual. Binary mode is > required to handle properly

Re: getting values from a text file (newby)

2009-02-01 Thread John Machin
On Feb 2, 6:18 am, vsoler wrote: > > r: in the open statement, why do you use 'rb' as 2nd argument? b is > supposed to be binary, and my file is text! Because unlike Stephen, r has read the csv manual. Binary mode is required to handle properly cases like '\n' embedded in a field -- something whi

Re: getting values from a text file (newby)

2009-02-01 Thread Steve Holden
Stephen Hansen wrote: > > > On Sun, Feb 1, 2009 at 9:24 AM, vsoler wrote: > > 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

Re: getting values from a text file (newby)

2009-02-01 Thread vsoler
On 1 feb, 19:02, Stephen Hansen wrote: > On Sun, Feb 1, 2009 at 9:24 AM, vsolerwrote: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 comm

Re: getting values from a text file (newby)

2009-02-01 Thread Stephen Hansen
On Sun, Feb 1, 2009 at 9:24 AM, vsoler wrote: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,

Re: getting values from a text file (newby)

2009-02-01 Thread r
On Feb 1, 11:50 am, Steve Holden wrote: > And then, to conert the last field to numbers? ... Are you asking me Steve? Well i did not want to short-circuit the OP's learning process by spoon-feeding him the entire answer. I thought i would give him a push in the right direction and observe the out

Re: getting values from a text file (newby)

2009-02-01 Thread Steve Holden
r wrote: > Try the csv module > > py> import csv > py> reader = csv.reader(open(csvfile, "rb")) > py> for row in reader: > print row > > > ['1', 'house', '2,5 '] > ['2', 'table', '6,7 '] > ['3', 'chair', '-4,5 '] And then, to conert the last field to numbers? ... regards Steve -- Steve

Re: getting values from a text file (newby)

2009-02-01 Thread r
Try the csv module py> import csv py> reader = csv.reader(open(csvfile, "rb")) py> for row in reader: print row ['1', 'house', '2,5 '] ['2', 'table', '6,7 '] ['3', 'chair', '-4,5 '] -- http://mail.python.org/mailman/listinfo/python-list

getting values from a text file (newby)

2009-02-01 Thread vsoler
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