zaxecivobuny

Untitled

Oct 20th, 2020
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def split_file(filename, output_size=2000, max_rows=160000):
  2.     with open(filename, encoding="utf8") as input_file:
  3.         current_row = 1
  4.         while current_row < max_rows:
  5.             current_output_file_num = current_row // output_size
  6.             output_filename = filename[:-4] + '_out_'
  7.             output_filename += str(current_output_file_num)
  8.             output_filename += ".csv"
  9.             print(output_filename)
  10.             with open(output_filename, 'w', encoding="utf8") as output_file:
  11.                 print("new file open")
  12.                 current_lines = 0
  13.                 while current_lines < output_size:
  14.                     line = input_file.readline()
  15.                     if not line:
  16.                         break
  17.                     else:
  18.                         line = str(current_row) + ',' + line
  19.                     output_file.write(line)
  20.                     current_row += 1
  21.                     current_lines += 1
  22.                 print("current file complete", current_lines, "lines in file")
  23.                 print("final_line:", line)
  24.                 if not line:
  25.                     break
  26.  
RAW Paste Data