IronPython使用str(object)转换对象遇到中文出错如何处理
IronPython脚本中使用str()函数将对象转换为字符串显示。但是遇到中文时出现如下错误:
>>import sys
>>str('您好')
'ascii' codec can't decode byte 0 in position 0: ordinal not in range
我参照网络上的将字符集修改为如下:
>>import sys
>>reload(sys)
>>sys.setdefaultencoding('utf8')
>>str('您好')
SystemError:没有可用于编码0的数据
应该怎么写才能正确转换?