SoFunction
Updated on 2024-11-15

Python's batch file creation example explanation

Batch file creation is actually very simple, just need to create a write file according to the need to write, write to close the current write file, create a new write file, write to close the current file,,, and so on in a continuous loop, the following is a simple example of a large file in accordance with every 1000 lines split into a small file.

The specific practices are as follows:

# -*- coding: utf-8 -*-

index = 0
count = 0
f_in = open("%" % index, "w")
with open("", "r") as f_out:
 for line in f_out:
  count += 1
  f_in.write(line)

  # After reading 1000 lines, the line count is set to zero, the small file number is incremented by one, and a new file is created to write the information.
  if count == 1000:
   f_in.close()
   count = 0
   index += 1
   f_in = open("%" % index, "w")

Above this Python's batch file creation example to explain is all that I have shared with you, I hope to give you a reference, and I hope you support me more.