zoukankan      html  css  js  c++  java
  • python:print含有中文的list

    Python 的 List 如果有中文的话, 会印出 xe4xb8... 等等的编码(如下所示), 要如何印出中文呢? 

    >>> a = ['中文', 'ab']
    >>> print a
    ['xe4xb8xadxe6x96x87', 'ab']


    下述列出几种作法:
    1.使用 decode('string_escape') 来达成


    >>> a = ['中文', 'ab']
    >>> print a
    ['xe4xb8xadxe6x96x87', 'ab']
    >>> print str(a).decode('string_escape')
    ['中文', 'ab']


    2.使用 uniout 来达成


    安装: sudo pip install uniout # Source code: https://github.com/moskytw/uniout
    >>> a = ['中文', 'ab']
    >>> import uniout
    >>> print a
    ['中文', 'ab']




    3.直接取用 _uniout 


    从上述 uniout Project 直接取用 _uniout.py


    >>> a = ['中文', 'ab']
    >>> import _uniout
    >>> print _uniout.unescape(str(a), 'utf8')
    ['中文', 'ab']

  • 相关阅读:
    odoo10 入门
    git 命令详细介绍
    odoo中Python实现小写金额转换为大写金额
    {DARK CTF } OSINT/Eye
    2020 12 18
    2020 12 17
    2020 12 16
    2020 12 15
    2020 11 14
    2020 11 13
  • 原文地址:https://www.cnblogs.com/robinunix/p/8289481.html
Copyright © 2011-2022 走看看