Created
December 20, 2012 15:24
-
-
Save ruoguluo/4345923 to your computer and use it in GitHub Desktop.
[Python] cut a big text file into small pieces of certain lines each
This file contains hidden or 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 -*- | |
# Filename:file_cut.py | |
path = raw_input('please enter the file path:') | |
savepath = raw_input('please enter the save path:(not include the last \'\\\')') | |
newname = raw_input('please enter the new name:') | |
fr = file(path,'r') | |
flag = True | |
i = 0 #??? | |
c = 1 #???? | |
while flag: | |
line = fr.readline() | |
i+=1 | |
if i < 10000: #??200000? | |
save =savepath +'\\'+ newname + str(c) + ".txt" | |
file(save,'a').write(line) | |
else: | |
i = 0 #????? | |
c+=1 #???+1 | |
continue #???? | |
if len(line) == 0: | |
flag = False | |
# if c == 5: | |
# flag = False | |
fr.close() | |
fs.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment