In numpy.core.numeric.py you will find loadtxt, which uses the following:: line = line[:line.find(comments)].strip() I believe there is a bug here (when a line has no comment). To illustrate:: >>> line = "12345" >>> comments = "#" >>> line[:line.find(comments)] '1234' So I propose this should be:: try: line = line[:line.index(comments)].strip() except ValueError: line = line.strip() Am I right? Cheers, Alan Isaac
On Thu, Nov 22, 2007 at 11:14:07PM -0500, Alan G Isaac wrote:
In numpy.core.numeric.py you will find loadtxt, which uses the following::
line = line[:line.find(comments)].strip()
I believe there is a bug here (when a line has no comment). To illustrate::
>>> line = "12345" >>> comments = "#" >>> line[:line.find(comments)] '1234'
Unless you are sure that line always ends with a "\n". This is the case in the code you are refering too. Unless I am missing some thing. Gaël
On Thu, Nov 22, 2007 at 11:14:07PM -0500, Alan G Isaac wrote:
In numpy.core.numeric.py you will find loadtxt, which uses the following:: line = line[:line.find(comments)].strip()
On Fri, 23 Nov 2007, Gael Varoquaux apparently wrote:
Unless you are sure that line always ends with a "\n". This is the case in the code you are refering too. Unless I am missing some thing.
I am not understanding your comment here. In the line of code above, is there a problem or not? Specifically, is it not the case that the last line of a text file is not guaranteed to have a terminator? E.g., URL:http://www.neppert.com/ioutilities/doc/com/neppert/io/TextReader.html Does this not raise the possibility that a digit will be clipped from the last line? Of course strip will afterwards strip any line terminators. Cheers, Alan Isaac
On Fri, Nov 23, 2007 at 07:58:13AM -0500, Alan G Isaac wrote:
On Thu, Nov 22, 2007 at 11:14:07PM -0500, Alan G Isaac wrote:
In numpy.core.numeric.py you will find loadtxt, which uses the following:: line = line[:line.find(comments)].strip()
On Fri, 23 Nov 2007, Gael Varoquaux apparently wrote:
Unless you are sure that line always ends with a "\n". This is the case in the code you are refering too. Unless I am missing some thing.
I am not understanding your comment here. In the line of code above, is there a problem or not?
I don't know.
Specifically, is it not the case that the last line of a text file is not guaranteed to have a terminator?
This is what I do not know, and I would appreciate to be enlightened.
Does this not raise the possibility that a digit will be clipped from the last line?
Yes. If the line does not end by a terminator you have a problem. Sorry if I am adding more confusion than help, I was just raising another question, or rather a comment on your question, rather than giving an answer. Gaël
On Fri, Nov 23, 2007 at 07:58:13AM -0500, Alan G Isaac wrote:
Specifically, is it not the case that the last line of a text file is not guaranteed to have a terminator? Does this not raise the possibility that a digit will be clipped from the last line?
On Fri, 23 Nov 2007, Gael Varoquaux apparently wrote:
Yes. If the line does not end by a terminator you have a problem.
I do not know how common this situation is, but: - it is common enough that some editors address it explicitly (e.g., Vim, Epsilon) - Java's TextReader addresses it explicitly URL:http://www.cs.arizona.edu/~reges/teachers/TextReader.html Based on these considerations an unterminated final line looks like a possibility. If so, perhaps that should be addressed by changing that line I pointed out in `loadtxt`. Cheers, Alan Isaac
participants (2)
-
Alan G Isaac
-
Gael Varoquaux