【发布时间】:2011-06-14 09:57:02
【问题描述】:
我已经问过here,但我很确定我不会得到答案。
- 复制 - 粘贴此 Python 代码:
- 执行它
- 在经典的 utf8 shell 中,它工作正常并显示“Coordonnées”,但在我家的薄荷终端中,它显示“CoordonnM-CM-)es”。知道如何使它工作,或者我应该看哪里(mintty 没有字符编码选项)?
代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys, time, random, copy, pprint
import termios, tty, fcntl
import thread, curses
import locale
def curses_main(stdscr, code):
curses.curs_set(0)
stdscr.addstr(2, 0, "Coordonnées")
stdscr.refresh()
# (1) = délai d'attente de 1/10 ème de seconde :
curses.halfdelay(1)
while True:
try:
c=stdscr.getch()
except:
c=-1
if 0<c<256:
if chr(c) in 'Qq':
break
def main():
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()
curses.wrapper(curses_main, code)
if __name__ == '__main__':
main()
更新
错误:我以为找到了它: 它到处都是以该代码开头的:
locale.setlocale(locale.LC_ALL, '')
所以我尝试了它并成功了:
locale.setlocale(locale.LC_ALL, 'fr_FR')
=> 强制使用法语
... 它有效,但仅适用于口音。 如果我尝试打印线条图字符:
stdscr.addstr(20,20, "─ │ ┌ ┘ ┐ └ ├ ┤ ┬ ┴ ┼ ═ ║ ╔ ╝ ╗ ╚ ╠ ╣ ╦ ╩ ╬")
给我:
M-b~T~@ M-b~T~B M-b~T~L M-b~T~X M-...
什么是头撞是vim 显示正确 那些字符。所以它似乎来自......来自python? 从我的 Windows/cygwin/mintty 可以工作:
env | grep -i lang
LANG=C.UTF-8
如果我在家中强制在我的 Windows/cygwin/mintty 中进行编码,不起作用:
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
这不起作用。
知道我可以在哪里看吗? python似乎正确地覆盖了语言环境设置......控制台配置正确,字体可以显示线条绘制字符,因为我用vim看到它们。所以想多了,可能是python的问题,也可能是curses的问题……
【问题讨论】:
-
该死! python 代码无法正确显示。如果您知道如何在此处显示,我可以请您转到显示代码的链接并在此处复制粘贴(并告诉我如何使其在此处工作=)非常感谢)
-
Windows Python 还是 Cygwin Python?
-
Cygwin => cammand line via mintty => 启动 Python 脚本
-
什么是 LC_ALL、LC_CTYPE 和 LANG 环境变量设置? mintty 选项的文本页面上的语言环境/字符集设置是什么?
-
我首先认为它有效,所以我发布了我自己的答案......但它只适用于特定的法语字符(如“é”)。画线字符不起作用。请参阅我的答案,我在其中放置了问题的更多详细信息。也许它不是来自薄荷控制台本身......