Re: Reading a two-column file into an array?

2007-08-02 Thread Gilles Ganault
On Tue, 31 Jul 2007 08:41:45 -0700, [EMAIL PROTECTED] (Alex Martelli) wrote: That's what 2.5's with statement is all about...: Thanks everyone. Python power :-) from __future__ import with_statement import csv with open('import.csv', 'rb') as f: for item in list(csv.reader(f,

Re: Reading a two-column file into an array?

2007-07-31 Thread Marc 'BlackJack' Rintsch
On Mon, 30 Jul 2007 21:57:17 -0700, Nagarajan wrote: a = [] import csv reader = csv.reader(open(filename, r), delimiter='\t' ) for row in reader: a.append( row ) I would keep a reference to the file to close it properly and the loop can be replaced by a call to `list()`: import csv

Re: Reading a two-column file into an array?

2007-07-31 Thread Alex Martelli
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Mon, 30 Jul 2007 21:57:17 -0700, Nagarajan wrote: a = [] import csv reader = csv.reader(open(filename, r), delimiter='\t' ) for row in reader: a.append( row ) I would keep a reference to the file to close it properly and the

[2.5] Reading a two-column file into an array?

2007-07-30 Thread Gilles Ganault
Hello I'm sure there's a much easier way to read a two-column, CSV file into an array, but I haven't found it in Google. Should I use the Array module instead? = a = [] i = 0 #itemTABitemCRLF p = re.compile(^(.+)\t(.+)$) for line in textlines: m = p.search(line) if m:

Re: [2.5] Reading a two-column file into an array?

2007-07-30 Thread Erik Max Francis
Gilles Ganault wrote: I'm sure there's a much easier way to read a two-column, CSV file into an array, but I haven't found it in Google. Should I use the Array module instead? The csv module? Or just .rstrip and .split? -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/

Re: Reading a two-column file into an array?

2007-07-30 Thread Nagarajan
On Jul 31, 9:03 am, Gilles Ganault [EMAIL PROTECTED] wrote: Hello I'm sure there's a much easier way to read a two-column, CSV file into an array, but I haven't found it in Google. Should I use the Array module instead? = a = [] i = 0 #itemTABitemCRLF p =

Re: Reading a two-column file into an array?

2007-07-30 Thread Jay Loden
Nagarajan wrote: On Jul 31, 9:03 am, Gilles Ganault [EMAIL PROTECTED] wrote: Hello I'm sure there's a much easier way to read a two-column, CSV file into an array, but I haven't found it in Google. Should I use the Array module instead? [...snip] a = [] import csv reader =