Python用\ n字符分割字符串

Kyl*_*yle 0 python split newline list

我有一个长字符串,其中包含许多\ n转义序列,这些转义序列应该是换行符。为了正确地编写要读取的字符串,我认为最好根据\ n字符分割字符串,然后将每个字符串分别写入结果列表中,以实现所需的效果。但是,这行不通,只是没有正确地拆分它们。以下是我的代码,为了清楚起见,我尝试将\ n和\ n都作为拆分,因为我试图在字符串中的文字\ n处拆分。谢谢你的帮助。

shellreturn = subprocess.check_output(["C:\Python34\python",root.wgetdir + "\html2text.py", keyworddir + "\\" + item])
print(shellreturn)
shelllist = (str(shellreturn).split("\\n"))
Run Code Online (Sandbox Code Playgroud)

vau*_*tah 5

你有bytes,不在str这里。将其解码为类似于字符串

shellreturn = shellreturn.decode()
Run Code Online (Sandbox Code Playgroud)

要么

shellreturn = str(shellreturn, 'utf-8')
Run Code Online (Sandbox Code Playgroud)

解码后,您可以使用.split('\n').splitlines()