On Feb 12, 11:02 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote: > En Fri, 13 Feb 2009 04:44:54 -0200, brianrpsgt1 <brianl...@cox.net> > escribió: > > > New to python.... I have a large file that I need to break upinto > > multiple smallerfiles. I need to break the large fileintosections > > where there are 65535 lines and then write thosesectionsto seperate > >files. I am familiar with opening and writingfiles, however, I am > > struggling with creating thesectionsand writing the different > >sectionsto their ownfiles. > > This function copies at most n lines from fin to fout: > > def copylines(fin, fout, n): > for i, line in enumerate(fin): > fout.write(line) > if i+1>=n: break > > Now you have to open the source file, create newfilesas needed and > repeatedly call the above function until the end of source file. You'll > have to enhace it bit, to know whether there are remaining lines or not. > > -- > Gabriel Genellina
Gabriel :: Thanks for the direction. Do I simply define fin, fout and n as variables above the def copylines(fin, fout, n): line? Would it look like this? fin = open('C:\Path\file') fout = 'C:\newfile.csv') n = 65535 def copylines(fin, fout, n): for i, line in enumerate(fin): fout.write(line) if i+1>=n: break Thanks B -- http://mail.python.org/mailman/listinfo/python-list