1, Python output Chinese How to solve
Method One:
With encode and decode.
Such as:
Import Os.path
Import Xlrd,sys
Filename= '/home/tom/desktop/1234.xls '
If not Os.path.isfile (Filename):
Raise Nameerror, "%s is not a valid filename"%filename
Bk=xlrd.open_workbook (Filename)
Shxrange=range (Bk.nsheets)
Print Shxrange
For x in Shxrange:
P=bk.sheets () [X].name.encode (' utf-8′)
Print P.decode (' utf-8′)
Method Two:
At the beginning of the file add
Reload (SYS)
Sys.setdefaultencoding (' utf8′) These 2 lines, and then try to run
2. How do I copy an object in Python?
In general, you can use the Copy.copy () method or the Copy.deepcopy () method, and almost all objects can be copied
Some objects can be copied more easily, and dictionaries has a copy method:
Newdict = Olddict.copy ()
3, the use and role of Python except?
Except is used to receive thrown exceptions
Python Interview Question Bank