从分隔文本中分离和写入唯一文件

时间:2017-10-11 11:19:24

标签: python-3.x text split

我跟着this tutorial here分隔并写出一个分隔的文本文件,但只输出一个文件。这是一个python2 - > 3期?请帮助。

filename = ('file path')

with open(filename) as Input:
    op = ''
    start = 0
    count = 1
    for x in Input.read().split("\n"):
        if (x == 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'):
            if (start == 1):
                with open(str(count) + '.txt', 'w') as Output:
                    Output.write(op)
                    Output.close()
                    op = ''
                    count = + 1
            else:
                start = 1
    Input.close()

1 个答案:

答案 0 :(得分:0)

你总是count = 1

更改此行:

count = + 1

count += 1