[Python-3000] Displaying strings containing unicode escapes
Nick Coghlan
ncoghlan at gmail.com
Mon May 5 04:22:28 CEST 2008
Stephen J. Turnbull wrote:
> Jim Jewett writes:
>
> > I realize that this is the traditional escape form, but I wonder if it
> > might be better to just use the character names instead of the hex
> > character codes.
>
> That would require changing the parser, no? Of all types, string had
> better roundtrip through repr()!
The string parser has understood Unicode names for quite some time
(examples use 2.5.1):
>>> print u"\N{GREEK SMALL LETTER ALPHA}"
α
>>> print u"\N{GREEK CAPITAL LETTER ALPHA}"
Α
>>> print u"\N{GREEK CAPITAL LETTER ALPHA WITH TONOS}"
Ά
Using the names gets fairly verbose compared to the hex escapes though:
>>> u"\N{GREEK SMALL LETTER ALPHA}"
u'\u03b1'
>>> u"\N{GREEK CAPITAL LETTER ALPHA}"
u'\u0391'
>>> u"\N{GREEK CAPITAL LETTER ALPHA WITH TONOS}"
u'\u0386'
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list