Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7348] StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 18, 2009, 10:58 AM

Post #1 of 3 (168 views)
Permalink
[issue7348] StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects

New submission from Jean-Paul Calderone <exarkun [at] divmod>:

cStringIO and file both accept -1 to readline to mean the same thing as
not passing any argument at all. StringIO, on the other hand, gets
totally confused:

>>> from StringIO import StringIO
>>> StringIO('a\nb\nfoo').readline(-1)
'a\nb\nfo'
>>>

----------
components: Library (Lib)
messages: 95438
nosy: exarkun
severity: normal
status: open
title: StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7348>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 20, 2009, 1:45 PM

Post #2 of 3 (139 views)
Permalink
[issue7348] StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects [In reply to]

Terry J. Reedy <tjreedy [at] udel> added the comment:

You specified neither version nor system.
On 3.1, Windows
>>> from io import StringIO as s
>>> s('a\nb\nfoo').readline(-1)

'a\n'

which, I gather, is what you describe as expected, although using -1 to
mean None is rather weird.

The 3.1 doc says only
"readline(limit=-1)
Read and return one line from the stream. If limit is specified, at most
limit bytes will be read."
which would imply that negative numbers are the same as 0.

So even in 3.1, either the behavior is wrong or the doc is incomplete.

----------
nosy: +tjreedy

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7348>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 20, 2009, 1:47 PM

Post #3 of 3 (138 views)
Permalink
[issue7348] StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects [In reply to]

Jean-Paul Calderone <exarkun [at] divmod> added the comment:

Python 2.6, Linux.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7348>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.