Skip to content

Instantly share code, notes, and snippets.

@4ox
Last active October 22, 2019 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4ox/17e938865d063672edfc205f5a38f678 to your computer and use it in GitHub Desktop.
Save 4ox/17e938865d063672edfc205f5a38f678 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from time import sleep
num=7
file_name = 'origin'
file_ext = '.csv'
first_line = True
files = {}
file_idx = 0
with open(file_name+file_ext, 'r', encoding = "utf-8" ) as f:
for line in f.readlines():
if first_line == True:
first_line = line
continue
key=line.split(",")[num]
if key not in files:
file_idx+=1
target = open(file_name + str(file_idx) + file_ext,'w')
target.write(first_line)
target.write(line)
files[key] = target
else:
target = files.get(key)
target.write(line)
for f in files:
files.get(f).close()
sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment