Python's annoying copy (\ xef \ xbf \ xbd) and xefxbf

Source: Internet
Author: User

Python's annoying copy (\ xef \ xbf \ xbd) and xefxbf

First, you must know what \ xef \ xbf \ xbd is.

>>> U' \ uFFFD '. encode ('utf-8')' \ xef \ xbf \ xbd'

From this we can know that \ xef \ xbf \ xbd is utf8 encoded '\ uFFFD', so what is this '\ uFFFD?

It turns out that there must be some words in the conversion process of Unicode and the old encoding system, which cannot be expressed by Unicode. Unicode officially uses a placeholder to represent these words, which is: U + fffd replacement character.

>>> "\ Xef \ xbf \ xbd". decode ("UTF-8") U' \ ufffd'

Therefore, if some characters in your text cannot be represented by unicode, it will be converted to \ xef \ xbf \ xbd when the python program reads it. If unicode is changed in some places, in this case

U' \ ufffd ', but you can no longer convert it to str.

If you happen to use these strings as Dictionary keys, a key_error error will be reported.

 

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.