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.




-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to