[SciPy-User] Ignore characters while reading text

Daπid davidmenhur@gmail....
Fri Jun 14 18:15:28 CDT 2013


On 14 June 2013 17:59, Matt Newville <newville@cars.uchicago.edu> wrote:
> What do you mean by "reading the data twice or thrice"?  I would have
> said text data in this snippet is stored in a string, but never read
> from a disk.    Once read from disk, the string.replace() method is
> fast, and StringIO makes a string look like a file-like structure, so
> I don't see how data is "read" multiple times.

Bad choice of words on my part, sorry. You are right you read from
disk only once, but you loop on it twice replacing (although this loop
is implemented in C, so probably quite fast). Actually, at this point,
it would be time to do some measurements. I have created a random
string of numbers, including some parenthesis, of one million
elements. One pass of replace takes ~1.2 ms, where the two replaces
together are 3 ms. So you were right, this is most probably fast
enough, and quite close to the most you can get.


More information about the SciPy-User mailing list