我想在我的程序中使用“Importação de petróleo”。
我该怎么做,因为所有编码都会给我错误,因为无法编码。
最佳答案
我认为您将字符串 __repr__
与其 __str__
混淆了:
>>> s = u"Importação de petróleo"
>>> s
u'Importa\xe7\xe3o de petr\xf3leo'
>>> print s
Importação de petróleo
\xe7
和 friend 没问题;它们只是那些特殊字符的编码表示。你无法避免它们,你不应该需要:)
关于python - 如何在 python 中编码 'Importação de petróleo' 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9644338/