Get the App
SLTechnology News&Howtos  ›  Development  › 

Two methods of how to realize Chinese output with python

Shulou Source: shulou.com Published: 2022-06-02 23:53:35 09月25日 Update

How to use python to achieve two methods of Chinese output, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

This Python learning tutorial mainly introduces two methods of python to realize Chinese output. An example analyzes the skills of Python to operate Chinese output. Partners in need can refer to it.

Method 1:

Use encode and decode

Such as:

Import os.pathimport xlrd,sysFilename='/home/tom/Desktop/1234.xls'if not os.path.isfile (Filename): raise NameError, "% s is not a valid filename"% Filenamebk=xlrd.open_workbook (Filename) shxrange=range (bk.nsheets) print shxrangefor x in shxrange: p=bk.sheets () [x] .name.encode ('utf-8') print p.decode (' utf-8')

Method 2:

Add at the beginning of the file:

Reload (sys) sys.setdefaultencoding ('utf8')

These two lines, try to run them again

On how to use python to achieve Chinese output of the two methods of the answer to share here, I hope the above content can be of some help to you, if you still have a lot of doubts unsolved, you can follow the industry information channel to learn more related knowledge.

Tags: Methods Chinese output questions more analysis help answers easy easy partner content learning tutorials examples case analysis guys buddies beginnings skills tutorials Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Xiaomi macOS MariaDB Shulou Tech Info