How can I split a text file into multiple text files using python?

前端 未结 5 488
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 10:22

I have a text file that contains the following contents. I want to split this file into multiple files (1.txt, 2.txt, 3.txt...). Each a new output file will be as the follow

5条回答
  •  囚心锁ツ
    2020-12-22 11:12

    Looks to me that the condition that you should be checking for is a line that contains just the carriage return (\n) character. When you encounter such a line, write the contents of the parsed file so far, close the file, and open another one for writing.

提交回复
热议问题