Author ezio.melotti
Recipients amaury.forgeotdarc, ezio.melotti, lemburg, vstinner
Date 2010-07-08.15:35:50
SpamBayes Score 0.00959171
Marked as misclassified No
Message-id <1278603353.96.0.392957722127.issue9198@psf.upfronthosting.co.za>
In-reply-to
Content
Yes, but as I said in the message I linked, that's *not* what I want to do.
I want to change only the behavior of the interactive interpreter and only when the string sent to stdout is not encodable (so only when the encoding is not UTF-*).

This can be done changing sys.displayhook, but I haven't figured out yet how to do it. The default displayhook (Python/sysmodule.c:71) calls PyFile_WriteObject (Objects/fileobject.c:139) passing the object as is and the stdout. PyFile_WriteObject then does the equivalent of sys.stdout.write(repr(obj)).
This is all done passing around unicode strings. Ideally we should try to encode the repr of the objects in displayhook using sys.stdout.encoding and 'backslashreplace', but then:
  1) we would have to decode the resulting byte string again before passing it to PyFile_WriteObject;
  2) we would have to find a way to write to sys.stdout a bytestring but I don't think that's possible (keep in mind that sys.stdout could also be some other object).

OTOH even if the intermediate step of encoding/decoding looks redundant it shouldn't affect performances too much, because it's not that common to print lot of text in the interactive interpreter and even in those cases probably performances are not so important. It would anyway be better to find another way to do it.
History
Date User Action Args
2010-07-08 15:35:54ezio.melottisetrecipients: + ezio.melotti, lemburg, amaury.forgeotdarc, vstinner
2010-07-08 15:35:53ezio.melottisetmessageid: <1278603353.96.0.392957722127.issue9198@psf.upfronthosting.co.za>
2010-07-08 15:35:52ezio.melottilinkissue9198 messages
2010-07-08 15:35:51ezio.melotticreate