How do I display unicode value stored in a string variable using ord()

lipska the kat lipskathekat at yahoo.co.uk
Sun Aug 19 06:13:11 EDT 2012


On 19/08/12 07:09, Steven D'Aprano wrote:
> This is a long post. If you don't feel like reading an essay, skip to the
> very bottom and read my last few paragraphs, starting with "To recap".

Thank you for this excellent post,
it has certainly cleared up a few things for me

[snip]

incidentally

 > But in UTF-16, ...

[snip]

 > py>  s = chr(0xFFFF + 1)
 > py>  a, b = s
 > py>  a
 > '\ud800'
 > py>  b
 > '\udc00'

in IDLE

Python 3.2.3 (default, May  3 2012, 15:51:42)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
 >>> s = chr(0xFFFF + 1)
 >>> a, b = s
Traceback (most recent call last):
   File "<pyshell#1>", line 1, in <module>
     a, b = s
ValueError: need more than 1 value to unpack

At a terminal prompt

[lipska at ubuntu ~]$ python3.2
Python 3.2.3 (default, Jul 17 2012, 14:23:10)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> s = chr(0xFFFF + 1)
 >>> a, b = s
 >>> a
'\ud800'
 >>> b
'\udc00'
 >>>

The date stamp is different but the Python version is the same

No idea why this is happening, I just thought it was interesting

lipska

-- 
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun



More information about the Python-list mailing list