我需要什么编码才能在 Windows XP 中的 cygwin 上使用 python 显示英镑符号(英镑符号)?
我有一个 python (2.5.4) 脚本,在 cygwin 中运行(在 Windows XP 的 DOS 框中)。 我想在输出中包含英镑符号 (£)。 如果这样做,我会收到此错误:
SyntaxError: Non-ASCII character '\xa3' in file dbscan.py on line 253, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
好的。 所以我查看了那个 PEP,现在尝试将其添加到我的脚本的开头:
# coding=cp437
这停止了错误,但输出在应该显示 £ 的地方显示了 ú。
我也尝试过 ISO-8859-1,结果相同。
有谁知道我需要哪种编码?
或者我可以去哪里寻找答案?
I have a python (2.5.4) script which I run in cygwin (in a DOS box on Windows XP). I want to include a pound sign (£) in the output. If I do so, I get this error:
SyntaxError: Non-ASCII character '\xa3' in file dbscan.py on line 253, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
OK. So I looked at that PEP, and now tried adding this to the beginning of my script:
# coding=cp437
That stopped the error, but the output shows ú where it should show £.
I've tried ISO-8859-1 as well, with the same result.
Does anyone know which encoding I need?
Or where I could look to find out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
井号的 Unicode 是 163(十进制)或十六进制的 A3,因此只要输出编码正常工作,无论脚本的编码如何,以下内容都应该有效。
The Unicode for a pound sign is 163 (decimal) or A3 in hex, so the following should work regardless of the encoding of your script, as long as the output encoding is working correctly.
尝试编码:
# -*-coding: utf-8 -*-
然后显示 '£' 符号:
try the encoding :
# -*- coding: utf-8 -*-
and then to display the '£' sign:
这里涉及两种编码:
看来您的输出编码现在已关闭。 如果它在 Cygwin 的终端窗口中运行,则您需要匹配该终端的编码。
编辑:我刚刚在(本机)Windows XP 终端窗口中运行了以下 Python 程序,认为它有点有趣:
156 肯定不是您尝试的 Latin1 编码中井号的代码点。 它似乎不在 Window 的代码页中1252 要么,我希望我的终端使用...奇怪。
There are two encodings involved here:
It seems your output encoding is off now. If this is running in a terminal window in Cygwin, it is that terminal's encoding that you need to match.
EDIT: I just ran the following Python program in a (native) Windows XP terminal window, thought it was slightly interesting:
156 is certainly not the codepoint for the pound sign in the Latin1 encoding you tried. It doesn't seem to be in Window's Codepage 1252 either, which I would expect my terminal to use ... Weird.