Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我尝试将 QString 转换为常规 python 字符串时出现此错误:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2029' in position 3: ordeal not in range(128)
我正在做的就是:
str(string)
string是 QString 但它给了我那个错误。我怎样才能解决这个问题?
string
strPython 2.x 中的名称具有误导性;由于历史原因,str is bytes- 一串字节而不是字符。如果您尝试将字符串转换为字节串,Python 默认使用 ASCII。在Python 2.x下简单使用unicode(string)获取字符串,或者切换到3.x,这里str其实是字符串类型。
str
str is bytes
unicode(string)