2015-09-06 13 views
6

私はしばらくこの問題に苦労してきました。私はHTMLに文字列を書き込もうとしていますが、いったんそれらを消去したらフォーマットに問題があります。ここでは例です:Python HTMLエンコーディング xc2 xa0

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" 

私はあなたがこれが起こると私は修正することができますどのように理由を説明することができます願っています。前もって感謝します! XA0 \ XC2 \

+2

ソース文字列のUnicode空白が異常であることを確認しましたか? –

答えて

14

に0xC2 0xA0を

非改行スペース

これは、UTF-8エンコーディングで目に見えない制御文字の一種である、いわゆるされることを意味します。さらに詳しい情報はwikipediaで確認してください。https://en.wikipedia.org/wiki/Non-breaking_space

質問に貼り付けた内容をコピーして、期待される出力を得ました。

+5

ありがとうございます。それはそれを修正する。私は内蔵: x.replace( "\ xc2 \ xa0"、 "") –

関連する問題