【问题标题】:Separate and write unique files from delimited text从分隔文本中分离和写入唯一文件
【发布时间】:2017-10-11 11:19:23
【问题描述】:

我正在关注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()

【问题讨论】:

    标签: python-3.x text split


    【解决方案1】:

    你总是有count = 1

    改变这一行:

    count = + 1
    

    count += 1
    

    【讨论】: