Python Coding problem Record

Source: Internet
Author: User

1,attributeerror: ' str ' object has no attribute ' decode ',:

Decode encode

bytes------> str (Unicode)------>bytes

Decode's target is dying bytes!

2,unicodedecodeerror: ' Utf-8 ' codec can ' t decode byte 0xb7 in position 0:invalid start byte

Often see this: \xb7\xfb\xe5\xab

>>> a= ' Fu Yi '

>>> a.encode (' gb2312 ')

B ' \xb7\xfb\xe5\xab '

>>> a.encode (' Utf-8 ')

B ' \xe7\xac\xa6\xe7\x80\x9a '

This shows Utf-8 and gb2312 to compile Chinese is similar to the beginning of "\x".

This error is using encoding decoding is not correct, you can try to use gb2312 to decode.

3. "\u65e0\u6cd5\u901a\u8fc7\u626b\u7801\u627e\u5230"

Syntaxerror:eol while scanning string literal quotation marks wrong in Chinese ...

This is the Unicode format, win under do not know why is not normal, normal to B = A.encode (' Utf-8 '). Decode (' Utf-8 ').


Python Coding problem Record

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.