Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97460 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2015-10-07 00:55 +0200 |
| Last post | 2015-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.
Re: Python 2 ‘print’, coercing arguments to Unicode Peter Otten <__peter__@web.de> - 2015-10-07 00:55 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-10-07 00:55 +0200 |
| Subject | Re: 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.
Back to top | Article view | comp.lang.python
csiph-web