Python-编码错误-cp850.py [英] Python - Encode error - cp850.py

查看:139
本文介绍了Python-编码错误-cp850.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python初学者,所以我希望这个问题可以轻松解决。

I am Python beginner so I hope this problem will be an easy fix.

我想按如下所示打印属性值:

I would like to print the value of an attribute as follows:

print (follower.city)

我收到以下错误消息:


文件 C:\Python34\lib\encodings\cp850.py,第19行,编码返回codecs.charmap_encode(input,self。错误,encoding_map)[0]
UnicodeEncodeError:'charmap'编解码器无法编码字符'\u0130'
0:字符映射到(未定义)

File "C:\Python34\lib\encodings\cp850.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: ‘charmap‘ codec can’t encode character ‘\u0130‘ 0: character maps to (undefined)

我认为问题是cp850.py在编码表中不包含相关字符。

I think the problem is that cp850.py does not contain the relevant character in the encoding table.

该问题的解决方案是什么?最终没有必要正确显示字符,但是必须避免错误消息。我需要修改cp850.py吗?

What would be the solution to this problem? No ultimate need to display the character correctly, but the error message must be avoided. Do I need to modify cp850.py?

很抱歉,如果以前已经解决了这个问题,但是我无法使用以前对该主题的回答来弄清楚。 / p>

Sorry if this question has been addressed before, but I was not able to figure it out using previous answers to this topic.

推荐答案

要打印字符串,必须首先将其从纯Unicode转换为输出设备支持的字节序列。这需要对正确的字符集进行编码,Python将该字符集标识为 cp850 -Windows控制台默认值。

To print a string it must first be converted from pure Unicode to the byte sequences supported by your output device. This requires an encode to the proper character set, which Python has identified as cp850 - the Windows Console default.

从Python 3.3开始,您可以通过在命令提示符处发出以下命令,将Windows控制台设置为使用UTF-8:

Starting with Python 3.3 you can set the Windows console to use UTF-8 with the following command issued at the command prompt:

chcp 65001

这应该可以解决您的问题,只要您已将窗口配置为使用包含字符。

This should fix your issue, as long as you've configured the window to use a font that contains the character.

这篇关于Python-编码错误-cp850.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆