私は、さまざまな言語のテキストを使用するアプリケーションを扱うので、特定の言語でテキスト(文字列)をソートする必要があります。Pythonの特定のロケールで特定のロケールのリストを並べ替える
現在、私が悪いのグローバルロケール設定をいじって回避策を、持っている、と私は生産に入れたくない:
default_locale = locale.getlocale(locale.LC_COLLATE)
def sort_strings(strings, locale_=None):
if locale_ is None:
return sorted(strings)
locale.setlocale(locale.LC_COLLATE, locale_)
sorted_strings = sorted(strings, cmp=locale.strcoll)
locale.setlocale(locale.LC_COLLATE, default_locale)
return sorted_strings
公式Pythonのロケールのドキュメントを明示的に保存と復元と言います悪い考えですが、任意の提案を与えるものではありません:http://docs.python.org/library/locale.html#background-details-hints-tips-and-caveats