在Python中使用的OS语言环境支持 [英] OS locale support for use in Python

查看:70
本文介绍了在Python中使用的OS语言环境支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下Python代码可在Windows计算机(Python 2.5.4)上运行,但不适用于Debian计算机(Python 2.5.0).我猜这取决于操作系统.

The following Python code works on my Windows machine (Python 2.5.4), but doesn't on my Debian machine (Python 2.5.0). I'm guessing it's OS dependent.

import locale
locale.setlocale( locale.LC_ALL, 'English_United States.1252' )

我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/locale.py", line 476, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

问题:

  • 它是否取决于操作系统?
  • 如何找到支持的语言环境 在Python中列出?
  • 如何在Windows之间进行匹配 语言环境和Debian语言环境?
  • Is it OS dependent?
  • How can I find the supported locale list within Python?
  • How can I match between Windows locales and Debian locales?

推荐答案

它取决于操作系统.

要获取可用的本地列表,可以在外壳中使用locale -a

To get the list of local available you can use locale -a in a shell

我认为您想要的本地语言类似于 Windows-1252

I think the local you want is something like Windows-1252

这篇关于在Python中使用的OS语言环境支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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