A quest for html.unescape("&nbsp")

This question already has an answer here:

  • Difference between __str__ and __repr__? 21 answers

  • By default, printing containers like tuples , lists and others will use the repr of their items. (In CPython, it was chosen to not implement <container>.__str__ and instead let object.__str__ fill its slot. The __str__ of object will then call tuple.__repr__ which then proceeds to call the repr of the elements it contains. See PEP 3140 for more.)

    Calling the repr for a string with escape codes (such as xa0 ) will, in effect, not escape them:

    print(repr(a))
    'homexa0-xa0study'
    

    To further verify, try print(s[0]) . By providing the str object in position 0 directly, python will invoke its __str__ and escape the hex correctly.

    链接地址: http://www.djcxy.com/p/28330.html

    上一篇: python 3.x

    下一篇: 寻求html.unescape(“&nbsp”)