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

Gilles Ganault nospam at nospam.com
Tue Jul 31 06:03:59 CEST 2007


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

p = re.compile("^(.+)\t(.+)$")

for line in textlines:
	m = p.search(line)
	if m:
		a[i,0] = m.group(1)
		a[i,1] = m.group(2)
		i = i + 1
for i in a.count:
	for j in 2:
		print a[i,j]

Thank you.

More information about the Python-list mailing list