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

Daπid davidmenhur at gmail.com
Wed Jan 15 05:25:26 EST 2014

On 15 January 2014 11:12, Hedieh Ebrahimi <hedieh.ebrahimi at amphos21.com>wrote:

> I try to print my fileContent array after I read it and it looks like this
> :
> ["b'C:\\\\Users\\\\Documents\\\\Project\\\\mytextfile1.txt'"
>  "b'C:\\\\Users\\\\Documents\\\\Project\\\\mytextfile2.txt'"
>  "b'C:\\\\Users\\\\Documents\\\\Project\\\\mytextfile3.txt'"]
> Why is this happening and how can I prevent it ?
> Also if I have a line that starts like this in my file, python will crash
> on me. how can i fix this ?

What is wrong with this case? If you are concerned about the multiple
backslashes, they are there because they are special symbols, and so they
have to be escaped (you actually want a backslash, not whatever else they
could mean).

Depending on what else is on the file, you may be better off reading the
file in pure python. Assuming there is nothing else, something like this
would work:

[line.strip() for line in open(filePath, 'r').readlines()]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140115/53bc3d43/attachment.html>

More information about the NumPy-Discussion mailing list