[Numpy-discussion] fromfile() for reading text (one more time!)

Christopher Barker Chris.Barker@noaa....
Sat Jan 9 19:32:48 CST 2010


Pauli Virtanen wrote:
> I don't really like handling newlines specially. For instance, I could
> have data like
> 
> 	1, 2, 3;
> 	4, 5, 6;
> 	7, 8, 9;
> 
> Allowing an "alternative separator" would sound better to me. The above
> data could then be read like
> 
> 	fromfile('foo.txt', sep=' , ', sep2=' ; ')
> 
> or perhaps
> 
> 	fromfile('foo.txt', sep=[' , ', ' ; '])

I like this syntax better, but:

1) Yes you "could" have data like that, but do you? I've never seen it. 
Maybe other have.

2) if you did, it would probably indicate something the user would want 
reserved, like the shape of the array.

And newlines really are a special case -- they have a special meaning, 
and they are very, very common (universal, even)!

So, it's just more code than I'm probably going to write.

If someone does want to write more code than I do, it would probably 
make sense to do what someone suggested in the ticket: write a optimized 
version of loadtxt in C.

Anyway. I'll think about it when I poke at the code more.

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the NumPy-Discussion mailing list