Re: Reading a two-column file into an array?
- From: Nagarajan <naga86@xxxxxxxxx>
- Date: Mon, 30 Jul 2007 21:57:17 -0700
On Jul 31, 9:03 am, Gilles Ganault <nos...@xxxxxxxxxx> 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
#item<TAB>item<CRLF>
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.
a = []
import csv
reader = csv.reader(open("filename", "r"), delimiter='\t' )
for row in reader:
a.append( row )
----------------------------
I don't think you can have multidimensional arrays.
Did you test you program? It did not work for me.
I think mine would suit your requirements as the output is a list of
lists.
.
- Follow-Ups:
- Re: Reading a two-column file into an array?
- From: Marc 'BlackJack' Rintsch
- Re: Reading a two-column file into an array?
- From: Jay Loden
- Re: Reading a two-column file into an array?
- References:
- [2.5] Reading a two-column file into an array?
- From: Gilles Ganault
- [2.5] Reading a two-column file into an array?
- Prev by Date: Re: [2.5] Reading a two-column file into an array?
- Next by Date: Re: Where do they tech Python officialy ?
- Previous by thread: Re: [2.5] Reading a two-column file into an array?
- Next by thread: Re: Reading a two-column file into an array?
- Index(es):
Relevant Pages
|