[Numpy-discussion] Using loadtxt() twice on same file freezes python

Pauli Virtanen pav at iki.fi
Thu Mar 26 13:41:56 EDT 2009


Fri, 27 Mar 2009 01:58:47 +0900, David Cournapeau wrote:
> On Fri, Mar 27, 2009 at 1:14 AM, Sander de Kievit
[clip]
>> On my PC the following code freezes python:
>>
>> [code]
>> import numpy as np
>> from StringIO import StringIO
>> c = StringIO("0 1\n2 3")
>> np.loadtxt(c)
>> np.loadtxt(c)
>> [/code]
[clip]

I see this too, on Numpy 1.2.1. It gets stuck at
{{{
>>> np.loadtxt(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../numpy-1.2.1-py2.5-linux-x86_64.egg/numpy/lib/io.py", line 
375, in loadtxt
    first_vals = split_line(first_line)
  File ".../numpy-1.2.1-py2.5-linux-x86_64.egg/numpy/lib/io.py", line 
356, in split_line
    line = line.split(comments)[0].strip()
KeyboardInterrupt
>>> np.__version__
'1.2.1'
}}}
However, on 1.4.0.dev6723, I get an exception:
{{{
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../numpy-1.4.0.dev-py2.5-linux-x86_64.egg/numpy/lib/io.py", line 
436, in loadtxt
    raise IOError('End-of-file reached before encountering data.')
}}}
There haven't been any changes to lib/io.py since branching off 1.3.x, so 
I believe it should also work OK on 1.3.0.

-- 
Pauli Virtanen




More information about the NumPy-Discussion mailing list