我对这个问题已经苦苦挣扎了一段时间。我试图将字符串写入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"
我希望您能够解释为什么会发生这种情况,以及我如何解决。提前感谢!