Last active
October 22, 2019 05:46
-
-
Save 4ox/17e938865d063672edfc205f5a38f678 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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