Tag: python unicode

Pythonstring到Unicode

可能重复: 我如何处理一个ASCIIstring作为unicode和unescape在python中的转义字符? 如何将unicode转义序列转换为pythonstring中的unicode字符 我有一个包含unicode字符的string,例如\u2026等等。不知怎的,它不是以unicode接收到的,而是作为一个str来接收的。 我如何将其转换回unicode? >>> a="Hello\u2026" >>> b=u"Hello\u2026" >>> print a Hello\u2026 >>> print b Hello… >>> print unicode(a) Hello\u2026 >>> unicode(a)显然unicode(a)不是答案。 那么是什么?

Python – 'ascii'编解码器不能解码字节

我很困惑。 我试图编码,但错误说can't decode… >>> "你好".encode("utf8") Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128) 我知道如何避免string上带有“u”前缀的错误。 我只是想知道为什么错误是“无法解码”时调用编码。 Python在做什么?

如何在Python中打印Unicode字符?

我想做一个词典,英文单词指向俄语和法语的翻译。 如何在Python中打印unicode字符? 另外,你如何将unicode字符存储在一个variables?

UnicodeEncodeError:'ascii'编解码器不能编码字符u'\ xa0'在位置20:序号不在范围内(128)

我在处理来自不同网页(不同网站)的文本中的Unicode字符时遇到了问题。 我正在使用BeautifulSoup。 问题是错误不总是可重现的; 它有时可以和一些页面一起工作,有时它通过抛出一个UnicodeEncodeError 。 我已经尝试了所有我能想到的事情,但是我还没有发现任何能够一致工作的东西,而没有抛出某种与Unicode相关的错误。 下面显示了导致问题的代码段之一: agent_telno = agent.find('div', 'agent_contact_number') agent_telno = '' if agent_telno is None else agent_telno.contents[0] p.agent_info = str(agent_contact + ' ' + agent_telno).strip() 当上面的代码片段运行时,这是在一些string上产生的堆栈跟踪: Traceback (most recent call last): File "foobar.py", line 792, in <module> p.agent_info = str(agent_contact + ' ' + agent_telno).strip() UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' […]