我已经和这件事斗争了一段时间。我试图将字符串写入HTML,但在清理完之后,格式有问题。下面是一个例子:
paragraphs = ['Grocery giant and household name Woolworths is battered and bruised. ',
'But behind the problems are still the makings of a formidable company']
x = str(" ")
for item in paragraphs:
x = x + str(item)
x
输出:
"Grocery giant and household name\xc2\xa0Woolworths is battered and\xc2\xa0bruised.
But behind the problems are still the makings of a formidable\xc2\xa0company"
期望输出:
"Grocery giant and household name Woolworths is battered and bruised.
But behind the problems are still the makings of a formidable company"
我希望你能解释为什么会发生这种事,以及我如何解决。提前谢谢!
\xc2\xa0表示0xC2 0xA0是所谓的
它是UTF-8编码中一种不可见的控制字符。关于它的更多信息请查看维基百科:https://en.wikipedia.org/wiki/Non-breaking_space
我复制了你在问题中粘贴的内容,得到了预期的结果。
相关问题 更多 >
编程相关推荐