特定文件格式的重复

时间:2018-01-22 16:09:55

标签: python windows encoding notepad++

我有一个文件格式,如果由GUI下载,它在Notepad ++中如下所示:

LF
headerline CR LF
dataline CR LF
...
last dataline LF
LF
headerline CR LF
....

等等

如果我通过python脚本运行它来进行自动备份:

output, error = process.communicate()
out = output.splitlines()
with open('test13.txt', 'w') as file:
    for line in out: 
        if line == '\n':
            file.write('\n')
        else: 
            file.write(line)
            file.write ('\n') 

我明白了:

headerline CR LF
dataline CR LF
dataline CR LF
....

如何处理?这似乎是一个编码问题?

如果我跑:

with io.open('test13.txt', 'wb') as file:
    file.write(output)

我得到了类似的结果。

谢谢!

0 个答案:

没有答案