Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97460 > unrolled thread

Re: Python 2 ‘print’, coercing arguments to Unicode

Started byPeter Otten <__peter__@web.de>
First post2015-10-07 00:55 +0200
Last post2015-10-07 00:55 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python 2 ‘print’, coercing arguments to Unicode Peter Otten <__peter__@web.de> - 2015-10-07 00:55 +0200

#97460 — Re: Python 2 ‘print’, coercing arguments to Unicode

FromPeter Otten <__peter__@web.de>
Date2015-10-07 00:55 +0200
SubjectRe: Python 2 ‘print’, coercing arguments to Unicode
Message-ID<mailman.436.1444172118.28679.python-list@python.org>
Ben Finney wrote:

>> I don't think this is possible with the print statement, but the
>> print() function can be replaced with anything you like:
> 
> 
> Hmm. I am more looking for something that doesn't involve replacing
> ‘print’, but rather to hook into whatever it uses to coerce the type of
> its arguments.
 
Have a look at PyFile_WriteObject in Objects/fileobject.c.
As I understand the code it basically does

if isinstance(obj) and stream.encoding is not None:
    s = obj.encode(stream.encoding))
else:
    s = str(obj)
stream.write(s)

There's no way to get the original object.



[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web