Unicode Objects in Tuples
Ben Finney
ben+python at benfinney.id.au
Fri Oct 11 04:30:40 EDT 2013
Stephen Tucker <stephen_tucker at sil.org> writes:
> I am using IDLE, Python 2.7.2 on Windows 7, 64-bit.
Python 2 is not as good at Unicode as Python 3. In fact, one of the
major reasons to switch to Python 3 is that it fixes Unicode behaviour
that was worse in Python 2.
> I have four questions:
>
> 1. Why is it that
[…]
> print (unicode_object, another_unicode_object)
> displays non-ASCII characters in the unicode objects as escape sequences
> (as repr() does)?
Python 3 behaves correctly for that::
>>> foo = "I ♡ Unicode"
>>> bar = "I ♥ Unicode"
>>> (type(foo), type(bar))
(<class 'str'>, <class 'str'>)
>>> print(foo)
I ♡ Unicode
>>> print(bar)
I ♥ Unicode
>>> print((foo, bar))
('I ♡ Unicode', 'I ♥ Unicode')
> 2. Given that this is actually *deliberately *the case (which I, at
> the moment, am finding difficult to accept)
I'm pretty sure it is not, since this is corrected in Python 3.
> what is the neatest (that is, the most Pythonic) way to get non-ASCII
> characters in unicode objects in tuples displayed correctly?
Switch to Python 3 :-)
--
\ “Timid men prefer the calm of despotism to the boisterous sea |
`\ of liberty.” —Thomas Jefferson |
_o__) |
Ben Finney
More information about the Python-list
mailing list