gpt4 book ai didi

python - 使用 UCS-4 的 Python Swig 绑定(bind)

转载 作者:太空宇宙 更新时间:2023-11-03 11:56:42 25 4
gpt4 key购买 nike

有谁知道是否有办法让 SWIG 将字符串编码为 Python 的 UCS-4?SWIG 文档指出,使用类型映射可以实现这一点,但未提供任何其他详细信息或示例。

就上下文而言,我正在使用一组 Python 脚本扩展 Blender 3D 软件。我们需要将这些脚本与各种机器人软件连接起来,我们使用 SWIG 来编译 Python 库。Blender 使用自己的 Python 3.2 预编译 --with-wide-unicode 选项,因此它使用 UCS-4 unicode 字符串。但是,默认 SWIG 将字符串编码为 UCS-2,因此在与 Blender 交互时,我总是会收到如下错误:“ undefined symbol :PyUnicodeUCS2_*”。

最佳答案

这是来自 SWIG 文档,也许你已经看到了:

At this time, SWIG provides limited support for Unicode and wide-character strings (the C wchar_t type). Some languages provide typemaps for wchar_t, but bear in mind these might not be portable across different operating systems. This is a delicate topic that is poorly understood by many programmers and not implemented in a consistent manner across languages. For those scripting languages that provide Unicode support, Unicode strings are often available in an 8-bit representation such as UTF-8 that can be mapped to the char * type (in which case the SWIG interface will probably work). If the program you are wrapping uses Unicode, there is no guarantee that Unicode characters in the target language will use the same internal representation (e.g., UCS-2 vs. UCS-4). You may need to write some special conversion functions.

所以听起来你应该将它映射到 char* ,然后在必要时弄清楚如何手动转换它。听起来一开始就很乱。

关于python - 使用 UCS-4 的 Python Swig 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7090957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com