【发布时间】:2014-05-08 06:14:28
【问题描述】:
我有一个长字符串,其中包含许多应该是换行符的 \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"))
【问题讨论】:
-
那么
shellreturn是什么? -
@frostnational,这里只是一小部分 shellreturn:b"PMSI Direct \n262 Old New Brunswick Rd., Unit M \nPiscataway, NJ 08854 \n800.238.1316 \n\n姓名\n\n公司\n\n电话\n\n电子邮件* _(必填)_\n\n![PMSI Direct, Inc.
-
it is just not splitting them correctly那它是怎么拆分的呢? -
我不确定,在frostnational 的帮助下,它现在似乎已经删除了输出中的\n,但它仍然是一行。