zoukankan      html  css  js  c++  java
  • linux : 各个发行版中修改python27默认编码为utf-8

    该方法可解决robot报错:'ascii' codec can't encode character u'xf1' in position 16: ordinal not in  range(128)

    在下面目录中新增文件:sitecustomize.py

    内容为

    #coding=utf-8
    import sys
    
    reload(sys)
    sys.setdefaultencoding('utf8')

    各个发行版放置位置:

    RedHat:

    /usr/local/python27/lib/python2.7/site-packages/

    Ubuntu

    /usr/lib/python2.7

    其他发行版

    /usr/local/lib/python.27/site-packages

    测试一下:使用sys.getdefaultencoding()测试,看返回是不是utf8

    [root@base7565 site-packages]# python
    Python 2.7.14 (default, Sep  2 2019, 14:26:39)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.getdefaultencoding()
    'utf8'
    >>>

    当robot通过cx_Oracle连接Oracle数据库时如果sql语句中出现中文,需要将文件内容修改为:

    #coding=utf-8
    import sys
    
    
    reload(sys)
    sys.setdefaultencoding('utf8')
    
    import os
    os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
  • 相关阅读:
    Leaf-spine data center architectures
    centreon 画图x轴乱码
    二分图匹配
    牛客练习赛17
    HDU-4550-贪心
    HDU-4511-ac自动机+dp
    UVA-11761-马尔可夫/记忆化搜索
    HDU-3853-期望/dp/坑
    HDU-4405-期望dp
    zoj-3329-期望/dp/方程优化
  • 原文地址:https://www.cnblogs.com/gcgc/p/11451065.html
Copyright © 2011-2022 走看看