D
Darren Dale
Hello,
I am trying to learn how to read a delimited file into a numarray. I
have a working strategy, but it doesnt seem very elegant: manually
changing whitespace delimiters to commas, evaluating the lines to a list
of tuples, creating a numarray object from that list.
Could I get some suggestions on how to do this more Pythonically? I have
to read pretty large files, so this approach is probably way to slow.
Here is my code:
from numarray import *
myFile=file('test.dat',mode='rt')
tempData=myFile.readlines()
data=[]
for line in tempData:
line=line.replace(' ',',')
line=line.replace('\n','')
data.append(eval(line))
data=array(data)
Thanks...
I am trying to learn how to read a delimited file into a numarray. I
have a working strategy, but it doesnt seem very elegant: manually
changing whitespace delimiters to commas, evaluating the lines to a list
of tuples, creating a numarray object from that list.
Could I get some suggestions on how to do this more Pythonically? I have
to read pretty large files, so this approach is probably way to slow.
Here is my code:
from numarray import *
myFile=file('test.dat',mode='rt')
tempData=myFile.readlines()
data=[]
for line in tempData:
line=line.replace(' ',',')
line=line.replace('\n','')
data.append(eval(line))
data=array(data)
Thanks...