Why does Mac OS X python vs peony CentOS Linux have different interpretations of \ U screens in lines?

Two python interpreter sessions. The first of python on CentOS. The second is from embedded python on Mac OS X 10.7. Why does the second session create lines two in length from the escape sequence \ U and subsequently throw an error?

$ python
Python 2.6.6 (r266:84292, Dec  7 2011, 20:48:22) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u'\U00000020'
u' '
>>> u'\U00000065'
u'e'
>>> u'\U0000FFFF'
u'\uffff'
>>> u'\U00010000'
u'\U00010000'
>>> len(u'\U00010000')
1
>>> ord(u'\U00010000')
65536

$ python
Python 2.6.7 (r267:88850, Jul 31 2011, 19:30:54) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
>>> u'\U00000020'
u' '
>>> u'\U00000065'
u'e'
>>> u'\U0000FFFF'
u'\uffff'
>>> u'\U00010000'
u'\U00010000'
>>> len(u'\U00010000')
2
>>> ord(u'\U00010000')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 2 found
+5
source share
1 answer

I'm not quite sure about this, but it may happen that your Mac OS X system uses a python narrow assembly, which is only 16 bits unicode for internal Unicode encoding and represents Unicode codes above 2 ** 16 as a pair characters (which explains len(u'\U00010000') == 2.

unichr(0x10000) OS X , . . python?, , IVH.

python, , python .

+4

All Articles