Coding problems and solutions for python2.7

  • 2020-05-12 02:50:50
  • OfStack

preface

The coding problem of Python is basically a problem that every novice will encounter, but as long as you fully grasp it, you will skip this hole. There are many changes in python2.7.

1. Modify the system code directly in the python file

The default encoding format is ascii, which we can directly change to utf-8


import sys
reload(sys)
sys.setdefaultencoding('utf-8')

2. When input and output, modify the encoding format


#  Decoding for GBK , again coded as UTF-8
html_doc = unicode(html_doc,'GBK').encode('UTF-8')

conclusion

Well, the above is the entire content of this article, I hope the content of this article to your study or work can bring 1 definite help, if you have questions you can leave a message to communicate.


Related articles: