[Numpy-discussion] using loadtxt to load a text file in to a numpy array

Chris Barker chris.barker at noaa.gov
Wed Jan 15 20:10:07 EST 2014


On Wed, Jan 15, 2014 at 3:58 PM, Julian Taylor <
jtaylor.debian at googlemail.com> wrote:

> > fileContent=loadtxt(filePath,dtype='S')
>
> this gives you bytes not a string, this can only be fixed by adding new
> dtypes,


or changing the behavior or dtype 'S', but yes, the other thread.

But the OP's problem was not that s/he got bytes, but that the content was
wrong -- he got the repr of bytes in a py3 string.

-

> same as using python str you get the output originally posted, bytes
> representation with duplicated slashes.
> This is a bug in loadtxt we need to fix independent of adding new dtypes.
>

yup.


> It is also independent of the encoding of the text file, loadtxt doesn't
> seem to be able to open other encodings than ascii/utf8 at all and has
> no option to tell it what the file is.
>

a key missing feature -- and I doubt it does utf-8 right, either.

as mentioned in my earlier mail this works for ascii:
>
>     np.loadtxt('test.txt',dtype=bytes).astype(str)
>

thanks -- I wasn't sure what astype would do for that. and what are you
getting then, unicode or ascii?

Thanks,
 -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 at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140115/10fa2c06/attachment.html>


More information about the NumPy-Discussion mailing list