Skip to content

Instantly share code, notes, and snippets.

@ruoguluo
Created December 20, 2012 15:24
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 ruoguluo/4345923 to your computer and use it in GitHub Desktop.
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
# -*- 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