在Windows XP中,我需要使用python在cygwin上显示一个GBP符号(英镑)吗? [英] What encoding do I need to display a GBP sign (pound sign) using python on cygwin in Windows XP?

查看:133
本文介绍了在Windows XP中,我需要使用python在cygwin上显示一个GBP符号(英镑)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python(2.5.4)脚本,我在cygwin中运行(在Windows XP的DOS框中)。我想在输出中加一英镑(£)。如果我这样做,我得到这个错误:

  SyntaxError:非ASCII字符'\xa3'在文件dbscan.py在第253行,但没有编码声明;有关详细信息,请参阅http://www.python.org/peps/pep-0263.html 

确定。所以我看了一下这个PEP,现在尝试把它添加到我的脚本开头:

 #coding = cp437 

停止了错误,但输出显示ú应该显示的位置。



我也尝试过ISO-8859-1,结果相同。



有谁知道我需要哪个编码?

解决方案

有两个编码涉及这里:




  • 您的源代码的编码,必须是正确的,以便您的输入文件意味着您的意思

  • 输出的编码,必须正确,才能按照预期显示符号。



似乎您的输出编码现在已经关闭了。如果这是在Cygwin的终端窗口中运行,那么该终端的编码需要匹配。



编辑:我刚刚运行在一个(本机)Windows XP终端窗口中的Python程序之后,认为这有点有趣:

 >>> ord(£)
156

156当然不是英镑的代码点在您尝试的Latin1编码中。它不会在Windows的代码页中似乎是 1252,我希望我的终端使用...奇怪。


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?

解决方案

There are two encodings involved here:

  • The encoding of your source code, which must be correct in order for your input file to mean what you think it means
  • The encoding of the output, which must be correct in order for the symbols emitted to display as expected.

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:

>>> ord("£")
156

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.

这篇关于在Windows XP中,我需要使用python在cygwin上显示一个GBP符号(英镑)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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