[New-bugs-announce] [issue7955] TextIOWrapper Buffering Inconsistent Between _io and _pyio

Andrew McNabb report at bugs.python.org
Thu Feb 18 07:41:17 CET 2010


New submission from Andrew McNabb <amcnabb at mcnabbs.org>:

The following snippet behaves differently in the C IO implementation than in the Python IO implementation:

  import sys
  sys.stdout.write('unicode ')
  sys.stdout.buffer.write(b'bytes ')

To test this, I have created two scripts, testpyio.py (using _pyio) and testio.py (using _io).  The output is as follows:

% python3 testpyio.py
unicode bytes
% python3 testio.py
bytes unicode
%

In my opinion, the behavior exhibited by _pyio is more correct.  It appears that to get the C implementation to print the lines in the correct order, there must be a flush in between the statements.  This extra flush would create a lot of overhead.

I am attaching the two test scripts.

The C implementation prints the output in the correct order if each write ends with a newline.

----------
components: IO
files: testpyio.py
messages: 99496
nosy: amcnabb
severity: normal
status: open
title: TextIOWrapper Buffering Inconsistent Between _io and _pyio
type: behavior
versions: Python 3.1
Added file: http://bugs.python.org/file16248/testpyio.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7955>
_______________________________________


More information about the New-bugs-announce mailing list