簡體   English   中英

如何將字符串轉換為列表,按字符串'\\ n \\ n \\ n \\ n \\ n'拆分?

[英]How to convert a string to a list, split by the string '\n\n\n\n\n'?

我有一個帶有文本的字符串,其中包含\\ n。 喜歡:

"Information moreinformation moreinformation \n\n\n\n\n Information moreinformation moreinformation \n\n\n\n\n Information moreinformation moreinformation"

現在我想要一個列表,由\\ n \\ n \\ n \\ n \\ n字符串拆分。 所以我想:

['Information moreinformation moreinformation', 'Information moreinformation moreinformation', 'Information moreinformation moreinformation']

我已經嘗試過了,但這不起作用。 然后我還有一個字符串。

with open ("file.txt", "r") as file:
    content = file.readlines()
    content = ' '.join(content)
    content.split('\n\n\n\n\n')

print (content)
   content =  content.split('\n\n\n\n\n')

嘗試這個。 但是,您沒有更改內容變量的數據類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM