2015-09-06 10 views
6

Ich habe mit diesem eine Zeitlang gekämpft. Ich versuche, Strings in HTML zu schreiben, habe aber Probleme mit dem Format, nachdem ich sie bereinigt habe. Hier ein Beispiel:Python HTML-Codierung 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 

Ausgang:

"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" 

gewünschte Ausgabe:

"Grocery giant and household name Woolworths is battered and bruised. 
But behind the problems are still the makings of a formidable company" 

Ich hoffe, Sie in der Lage zu erklären, warum dies geschieht und wie kann ich das beheben. Danke im Voraus!

+2

Haben Sie in Ihrer Quellzeichenfolge nach ungewöhnlichen Unicode-Leerzeichen gesucht? –

Antwort

14

\ xc2 \ xa0 bedeutet 0xC2 0xA0 sogenannte wird

Geschütztes Leerzeichen

Es ist eine Art unsichtbare Steuerzeichen in UTF-8-Codierungen. Weitere Informationen dazu finden Sie in der Wikipedia: https://en.wikipedia.org/wiki/Non-breaking_space

Ich habe kopiert, was Sie in die Fragen eingefügt haben und die erwartete Ausgabe erhalten.

+5

Vielen Dank. Das behebt es. Ich habe eingebaut: x.replace ("\ xc2 \ xa0", "") –

Verwandte Themen