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


Groups > comp.lang.python > #97463

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

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Python 2 ‘print’, coercing arguments to Unicode
Date 2015-10-07 10:23 +1100
References <851td81g08.fsf@benfinney.id.au> <85wpv0z368.fsf@benfinney.id.au> <201510061248.t96CmCWP011700@fido.openend.se> <85si5nzo6y.fsf@benfinney.id.au> <mv1jgc$hhl$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.439.1444173810.28679.python-list@python.org> (permalink)

Show all headers | View raw


Peter Otten <__peter__@web.de> writes:

> 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)

So as I understand it I'm looking for the hypothetical

    from __future__ import print_coerce_args_to_unicode

and without that, I'm stuck with the hard-coded ‘str’ coercion.

Thanks, at least now I can stop flailing to try to get it working.

-- 
 \       “Fear him, which after he hath killed hath power to cast into |
  `\   hell; yea, I say unto you, Fear him.” –Jesus, as quoted in Luke |
_o__)                                                             12:5 |
Ben Finney

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python 2 ‘print’, coercing arguments to Unicode Ben Finney <ben+python@benfinney.id.au> - 2015-10-07 10:23 +1100

csiph-web