[SciPy-user] efficiently importing ascii data

Darren Dale dd55 at cornell.edu
Mon Nov 14 08:47:44 CST 2005


On Monday 14 November 2005 08:10 am, Bill Dandreta wrote:
> Darren Dale wrote:
> >I was wondering if the fromstring function could be expanded to include
> > ascii strings. Right now, I'm considering reading my messy file, creating
> > a neatly formatted string, writing that string back into a temporary
> > file, and then using the fromfile function. It would be so much nicer to
> > just create the array from the string itself.
> >
> >Darren
>
> You might be able to use an 'in memory file' using StringIO from the
> StringIO module.

I don't think fromfile plays nice with StringIO:

from scipy import *
from StringIO import StringIO

f=StringIO('1e7,150,1e-5') 
# at this point, the file-like object f should be ready for reading 
x=fromfile(f,sep=',')

Traceback (most recent call last):
  File "test.py", line 5, in ?
    x=fromfile(f,sep=',')
IOError: first argument must be an open file

Darren



More information about the SciPy-user mailing list