Python Interview Question Bank

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.