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

2015-10-06 Thread Peter Otten
Ben Finney wrote: > Ben Finney writes: > >> In Python 2.7, I am seeing this behaviour for ‘print’:: >> >> Python 2.7.10 (default, Sep 13 2015, 20:30:50) >> [GCC 5.2.1 20150911] on linux2 >> Type "help", "copyright", "credits" or "license" for more >>

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

2015-10-06 Thread Ben Finney
Laura Creighton writes: > Hmm, now that I read the six document again > @six.python_2_unicode_compatible Peter Otten <__pete...@web.de> writes: > I don't think this is possible with the print statement, but the > print() function can be replaced with anything you like:

Python 2 ‘print’, coercing arguments to Unicode

2015-10-06 Thread Ben Finney
Howdy all, In Python 2.7, I am seeing this behaviour for ‘print’:: Python 2.7.10 (default, Sep 13 2015, 20:30:50) [GCC 5.2.1 20150911] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from __future__ import unicode_literals >>> from

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

2015-10-06 Thread Peter Otten
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 >

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

2015-10-06 Thread Terry Reedy
On 10/6/2015 6:45 AM, Ben Finney wrote: Ben Finney writes: How can I convince ‘print’, everywhere throughout a module, that it should coerce its arguments using ‘unicode’? Use Python 3. I am only half joking. Switching to unicode instead of bytes as the

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

2015-10-06 Thread Ben Finney
Terry Reedy writes: > On 10/6/2015 6:45 AM, Ben Finney wrote: > > Ben Finney writes: > > > How can I convince ‘print’, everywhere throughout a module, that it > > should coerce its arguments using ‘unicode’? > > Use Python 3. I am only half joking.

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

2015-10-06 Thread Ben Finney
Peter Otten <__pete...@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

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

2015-10-06 Thread Ben Finney
Ben Finney writes: > In Python 2.7, I am seeing this behaviour for ‘print’:: > > Python 2.7.10 (default, Sep 13 2015, 20:30:50) > [GCC 5.2.1 20150911] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from

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

2015-10-06 Thread Laura Creighton
I think the thing you want to converse is your stringIO not your print. I think you do this using six.stringIO https://pythonhosted.org/six/ But I have only read the doc, not done this in practice. Laura -- https://mail.python.org/mailman/listinfo/python-list

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

2015-10-06 Thread Laura Creighton
Hmm, now that I read the six document again @six.python_2_unicode_compatible seems exactly what you are asking for ... https://pythonhosted.org/six/ Laura -- https://mail.python.org/mailman/listinfo/python-list