I try to understand how works numpy.getfromtxt method and io.StringIO. On the officical website(https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/num
Consider upgrading numpy because for the current version of numpy
, your code just works as written. See the mention in 1.14.0 release note highlights and the section Encoding argument for text IO functions for the relevant changes in np.genfromtxt
.
For older numpy, you use a string object for the input but the docs you linked say:
Note that generators must return byte strings in Python 3k.
So do what the docs say and give it a byte string:
import io
s = io.BytesIO(b"1,1.3,abcde")