Ich habe eine Zeichenfolge mit Text und \ n's drin. Wie:Wie konvertiert man einen String in eine Liste, geteilt durch die Zeichenkette ' n n n n n'?
"Information moreinformation moreinformation \n\n\n\n\n Information moreinformation moreinformation \n\n\n\n\n Information moreinformation moreinformation"
Jetzt möchte ich eine Liste, geteilt durch die \ n \ n \ n \ n \ n Zeichenfolgen. Also ich will:
['Information moreinformation moreinformation', 'Information moreinformation moreinformation', 'Information moreinformation moreinformation']
Ich habe das schon versucht, aber das funktioniert nicht. Dann habe ich noch eine Schnur.
with open ("file.txt", "r") as file:
content = file.readlines()
content = ' '.join(content)
content.split('\n\n\n\n\n')
print (content)
Strings sind ** unveränderlich **. Alle Operationen an Strings * geben * das Ergebnis zurück, anstatt das Argument zu ändern. Daher: 'content = content.split ('...')' macht den Trick. – Bakuriu
Danke! Es hat funktioniert :) –
Geist ein Beispiel für Ihre Textdatei zu veröffentlichen? ... Vielleicht kann dies besser gelöst werden –