Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- num=0
- file_name = 'origin'
- file_ext = '.csv'
- first_line = True
- files = {}
- file_idx = 0
- with open(file_name+file_ext, 'r') 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement