Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os as os
- def write_new(outputfn, countfn):
- outputfn1 = outputfn + str(countfn) + ".txt"
- text_file = open(outputfn1, "w")
- return text_file
- def main():
- os.system('clear')
- print "<<<Using full name including suffix(.txt etc)>>>\n"
- filename = str(raw_input("What is the input filename? >"))
- limit = str(raw_input('How many lines should I split it to? > '))
- os.system('clear')
- print "<<<Just type a name and I'll save them as .txt files>>>\n"
- outputfn = str(raw_input("What do you want to call the output files?"))
- outputfn1 = outputfn + "0.txt"
- fin = open(filename)
- count, countfn = 1, 0
- text_file = open(outputfn1, "w")
- for line in fin:
- line1 = line.strip()
- if int(count) == int(0):
- try: text_file.close()
- except: pass
- text_file = write_new(outputfn, countfn)
- countfn += 1
- text_file.write(line1)
- text_file.write("\n")
- count += 1
- if count == int(limit): count = 0
- text_file.close()
- os.system('clear')
- print "Your files are in the same folder as this program"
- main()
Advertisement
Add Comment
Please, Sign In to add comment