Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:Python': 0.05; 'none:': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'hmm.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Unicode': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'object.': 0.22; 'replacing': 0.23; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X -Complaints-To:1': 0.26; 'function': 0.28; 'print': 0.30; 'code': 0.30; 'replaced': 0.35; 'something': 0.35; 'but': 0.36; 'possible': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'anything': 0.38; 'skip:o 20': 0.38; 'whatever': 0.39; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'more': 0.63; 'statement,': 0.66; 'subjectcharset:utf-8': 0.71 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Python 2 =?UTF-8?B?4oCYcHJpbnTigJks?= coercing arguments to Unicode Date: Wed, 07 Oct 2015 00:55:03 +0200 Organization: None References: <851td81g08.fsf@benfinney.id.au> <85wpv0z368.fsf@benfinney.id.au> <201510061248.t96CmCWP011700@fido.openend.se> <85si5nzo6y.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p57bd9a32.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1444172118 news.xs4all.nl 23838 [2001:888:2000:d::a6]:43086 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97460 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.