【发布时间】:2019-08-24 18:11:58
【问题描述】:
当我运行这个 Python 2.7 代码时(编辑:更新了代码)
import io
x = io.StringIO(u'\ud801')
CPython 运行良好,但 IronPython 抛出以下错误:
UnicodeEncodeError:
Unable to translate Unicode character \uD801 at index 0 to specified code page.
我猜这是因为U+D801 is an unpaired surrogate and thus an invalid character,但是哪个实现在这里显示了正确的行为?这段代码应该抛出还是不抛出?
【问题讨论】:
标签: python python-2.7 unicode encoding surrogate-pairs