shamilbi <shami...@gmail.com> added the comment:
>
> Trunk and release26-maint were recently changed (r71657, r71658) to use
> the following logic, which differs from the code snippet you posted.
>
> if (isinstance(msg, unicode) and
> getattr(stream, 'encoding', None)):
> stream.write(fs.decode(stream.encoding) % msg)
> else:
> stream.write(fs % msg)
>
> If the stream is stderr and you are passing a unicode msg, the else
> branch will not be taken; as long as the stream has an encoding
> attribute, it should output correctly.
>
> The change was made when another, similar issue was posted by another
> user (issue #5768).
>
> Can you confirm what happens with the current code as it is in
> release26-maint? ÑпаÑибо!
it still doesn't work for console (but OK for files).
the following works in both cases:
if (isinstance(msg, unicode) and
getattr(stream, 'encoding', None) and
(stream == sys.stdout or stream == sys.stderr)):
stream.write(fs % msg.encode(stream.encoding))
else:
stream.write(fs % msg)
i think it's all about the difference betwin print(msg) and
sys.stdout.write('%s\n' % msg)
shamil
----------
Added file: http://bugs.python.org/file13734/unnamed
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5170>
_______________________________________
<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left:
1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;">Trunk and release26-maint were recently changed (r71657, r71658) to
use<br>
the following logic, which differs from the code snippet you posted.<br>
<br>
          if (isinstance(msg, unicode) and<br>
            getattr(stream, 'encoding',
None)):<br>
            stream.write(fs.decode(stream.encoding) %
msg)<br>
<div class="im"> Â Â Â Â Â Â Â Â Â Â else:<br>
            stream.write(fs % msg)<br>
<br>
</div>If the stream is stderr and you are passing a unicode msg, the else<br>
branch will not be taken; as long as the stream has an encoding<br>
attribute, it should output correctly.<br>
<br>
The change was made when another, similar issue was posted by another<br>
user (issue #5768).<br>
<br>
Can you confirm what happens with the current code as it is in<br>
release26-maint? ÑпаÑибо!</blockquote><div> </div></div>it still
doesn't work for console (but OK for files).<br><br>the following works in
both cases:<br>if (isinstance(msg, unicode) and<br>
   getattr(stream, 'encoding', None) and<br>   (stream ==
sys.stdout or stream == sys.stderr)):<br>Â Â Â stream.write(fs %
msg.encode(stream.encoding))<br>else:<br>Â Â Â Â stream.write(fs %
msg)<br><br>i think it's all about the difference betwin print(msg) and
sys.stdout.write('%s\n' % msg)<br>
<br>shamil<br>
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com