本文介绍了UnicodeEncodeError:"ascii"编解码器无法对位置0-6处的字符进行编码:序数不在范围内(128)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有可以找到的解决方案,但是似乎没有任何效果:

Ι've tried all the solution that I could find, but nothing seems to work:

teext = str(self.tableWidget.item(row, col).text())

我正在用希腊语写作...

I'm writing in greek by the way...

推荐答案

很显然,self.tableWidget.item().text()返回Unicode,并且您需要使用decode方法:

Clearly, self.tableWidget.item().text() returns Unicode, and you need to use the decode method instead:

self.tableWidget.item(row, col).text().encode('utf8')

您真的想查看 Python Unicode HOWTO ,以充分理解unicode对象及其字节编码.

You really want to review the Python Unicode HOWTO to fully appreciate the difference between a unicode object and it's byte encoding.

另一篇优秀的文章是每个软件开发人员绝对,肯定地必须了解Unicode和字符集的绝对最低要求(没有借口!),Joel Spolsky(堆栈溢出背后的人之一).

Another excellent article is The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!), by Joel Spolsky (one of the people behind Stack Overflow).

这篇关于UnicodeEncodeError:"ascii"编解码器无法对位置0-6处的字符进行编码:序数不在范围内(128)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 19:01