寻求html.unescape(“&nbsp”)

这个问题在这里已经有了答案:

  • __str__和__repr__之间的区别? 21个答案

  • 默认情况下,打印容器(如tupleslists等)将使用其项目的repr 。 (在CPython中,它选择不实现<container>.__str__ ,而是让object.__str__填充它的槽,然后__str__ object调用tuple.__repr__ ,然后继续调用它所包含元素的repr 。 3140)。)

    实际上,使用转义码(例如xa0 )为repr调用一个字符串将不会转义它们:

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

    要进一步验证,请尝试print(s[0]) 。 通过直接在位置0提供str对象,python将调用__str__并正确地转义十六进制。

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

    上一篇: A quest for html.unescape("&nbsp")

    下一篇: Difference between variable and print variable