Python2.7 encoding problem and solution, python2.7 Encoding

Source: Internet
Author: User

Python2.7 encoding problem and solution, python2.7 Encoding

Preface

The encoding problem of Python is basically a problem that every newbie will encounter, but as long as he has mastered it completely, he will skip this pitfall and leave it alone. The following describes the Encoding Problems Encountered in python2.7, let's take a look.

1. directly modify the system code in the python File

The default encoding format is ascii, which can be changed to UTF-8.

Import sysreload (sys) sys. setdefaultencoding ('utf-8 ')

Ii. Modify the encoding format during input/output

# Decoded to GBK, encoded again as UTF-8html_doc = unicode (html_doc, 'gbk'). encode ('utf-8 ')

Summary

Well, the above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.

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.