Rei*_*ica 62 python unicode ucs2
正如标题所说的那样.
$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
Run Code Online (Sandbox Code Playgroud)
搜索官方文档,我发现了这个:
sys.maxunicode:一个整数,给出Unicode字符支持的最大代码点.其值取决于配置选项,该选项指定Unicode字符是否存储为UCS-2或UCS-4.
这里不清楚的是 - 哪些值对应于UCS-2和UCS-4.
该代码预计适用于Python 2.6+.
Ste*_*tef 121
使用--enable-unicode = ucs4构建时:
>>> import sys
>>> print sys.maxunicode
1114111
Run Code Online (Sandbox Code Playgroud)
使用--enable-unicode = ucs2构建时:
>>> import sys
>>> print sys.maxunicode
65535
Run Code Online (Sandbox Code Playgroud)
Mar*_*wis 19
UCS-2为0xFFFF(或65535),UCS-4为0x10FFFF(或1114111):
Py_UNICODE
PyUnicode_GetMax(void)
{
#ifdef Py_UNICODE_WIDE
return 0x10FFFF;
#else
/* This is actually an illegal character, so it should
not be passed to unichr. */
return 0xFFFF;
#endif
}
Run Code Online (Sandbox Code Playgroud)
UCS-4模式中的最大字符由UTF-16中可表示的maxmimum值定义.
小智 11
我有过同样的问题一次.我在我的wiki上为自己记录了这个
http://arcoleo.org/dsawiki/Wiki.jsp?page=Python%20UTF%20-%20UCS2%20or%20UCS4
我写 -
import sys
sys.maxunicode > 65536 and 'UCS4' or 'UCS2'
Run Code Online (Sandbox Code Playgroud)
小智 8
sysconfig将从python的配置变量中告诉unicode大小.
可以像这样查询构建标志.
Python 2.7:
import sysconfig
sysconfig.get_config_var('Py_UNICODE_SIZE')
Run Code Online (Sandbox Code Playgroud)
Python 2.6:
import distutils
distutils.sysconfig.get_config_var('Py_UNICODE_SIZE')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
37333 次 |
最近记录: |