zoukankan      html  css  js  c++  java
  • python,shell,locale,charset

    windows下,python控制台,编码 为gbk

    用户输入为gbk,python内部用unicode

    zi = u'字'

    gbk输入 -> unicode内部表示

    >>> zi
    u'u5b57'  内部表示

    >>> print zi

    字     内部表示->gbk输出

    把内部表示转换为另一种编码存储

    输出时,系统认为仍是unicode表示,因此输出乱码

    查看windows控制台编码:

    右键属性

    python控制台编码:

    http://docs.python.org/2/library/locale.html

    locale.getdefaultlocale([envvars])

    Tries to determine the default locale settings and returns them as a tuple of the form (language code, encoding).

    According to POSIX, a program which has not called setlocale(LC_ALL, '') runs using the portable 'C' locale. Callingsetlocale(LC_ALL, '') lets it use the default locale as defined by the LANG variable. Since we do not want to interfere with the current locale setting we thus emulate the behavior in the way described above.

    To maintain compatibility with other platforms, not only the LANG variable is tested, but a list of variables given as envvars parameter. The first found to be defined will be used. envvars defaults to the search path used in GNU gettext; it must always contain the variable name LANG. The GNU gettext search path contains 'LANGUAGE''LC_ALL''LC_CTYPE', and 'LANG', in that order.

    Except for the code 'C', the language code corresponds to RFC 1766language code and encoding may be None if their values cannot be determined.

    >>> locale.getdefaultlocale()
    ('zh_CN', 'cp936')
    >>>

     wiki cp936约等于gbk

  • 相关阅读:
    linux查看系统类型和版本
    javascript 中的继承实现, call,apply,prototype,构造函数
    redis原理分析
    HashTable 简述
    算法之 快速排序
    react js 之生命周期
    Java源代码编译过程
    Java字节码文件结构---概述
    Java程序运行时内存划分
    数据结构--汉诺塔--借助栈实现非递归---Java
  • 原文地址:https://www.cnblogs.com/threef/p/3316333.html
Copyright © 2011-2022 走看看