Re: Text processing and file creation

2007-09-07 Thread Paddy
On Sep 7, 3:50 am, George Sakkis <[EMAIL PROTECTED]> wrote: > On Sep 5, 5:17 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > If this was a code golf challenge, I'd choose the Unix split solution and be both maintainable as well as concise :-) - Paddy. -- http://mail.python.org/mailman/li

Re: Text processing and file creation

2007-09-06 Thread George Sakkis
On Sep 5, 5:17 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Sep 5, 1:28 pm, Paddy <[EMAIL PROTECTED]> wrote: > > > On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > > I have a text source file of about 20.000 lines.>From this file, I like > > > to write the fir

Re: Text processing and file creation

2007-09-06 Thread Ricardo Aráoz
Shawn Milochik wrote: > On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> I have a text source file of about 20.000 lines. >> >From this file, I like to write the first 5 lines to a new file. Close >> that file, grab the next 5 lines write these to a new file... grabbing >> 5 lines and cre

Re: Text processing and file creation

2007-09-06 Thread Shawn Milochik
Here's my solution, for what it's worth: #!/usr/bin/env python import os input = open("test.txt", "r") counter = 0 fileNum = 0 fileName = "" def newFileName(): global fileNum, fileName while os.path.exists(fileName) or fileName == "": fileNum += 1 x = "%0.5d" % fileN

Re: Text processing and file creation

2007-09-06 Thread Arnau Sanchez
[EMAIL PROTECTED] escribió: > I am still wondering how to do this efficiently in Python (being kind > of new to it... and it's not for homework). You should post some code anyway, it would be easier to give useful advice (it would also demonstrate that you put some effort on it). Anyway, here i

Re: Text processing and file creation

2007-09-06 Thread Alberto Griggio
> Thanks for making me aware of the (UNIX) split command (split -l 5 > inFile.txt), it's short, it's fast, it's beautiful. > > I am still wondering how to do this efficiently in Python (being kind > of new to it... and it's not for homework). Something like this should do the job: def nlines(num

Re: Text processing and file creation

2007-09-05 Thread Arnaud Delobelle
On Sep 6, 12:46 am, Steve Holden <[EMAIL PROTECTED]> wrote: > Arnaud Delobelle wrote: [...] > > print "all done!" # All done > > print "Now there are 4000 files in this directory..." > > > Python 3.0 - ready (I've used open() instead of file()) > > bzzt! > > Python 3.0a1 (py3k:57844, Aug 31

Re: Text processing and file creation

2007-09-05 Thread Ginger
and u can parse lines from read buffer freely. have fun! - Original Message - From: "Shawn Milochik" <[EMAIL PROTECTED]> To: Sent: Thursday, September 06, 2007 1:03 AM Subject: Re: Text processing and file creation > On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTE

Re: Text processing and file creation

2007-09-05 Thread Steve Holden
Arnaud Delobelle wrote: [...] > from my_useful_functions import new_file, write_first_5_lines, > done_processing_file, grab_next_5_lines, another_new_file, write_these > > in_f = open('myfile') > out_f = new_file() > write_first_5_lines(in_f, out_f) # write first 5 lines > close(out_f) > while not

Re: Text processing and file creation

2007-09-05 Thread Arnaud Delobelle
On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines.>From this file, I like to > write the first 5 lines to a new file. Close > > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files

Re: Text processing and file creation

2007-09-05 Thread [EMAIL PROTECTED]
On Sep 5, 1:28 pm, Paddy <[EMAIL PROTECTED]> wrote: > On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > I have a text source file of about 20.000 lines.>From this file, I like to > > write the first 5 lines to a new file. Close > > > that file, grab the next 5 lines write t

Re: Text processing and file creation

2007-09-05 Thread Paddy
On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines.>From this file, I like to > write the first 5 lines to a new file. Close > > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files

Re: Text processing and file creation

2007-09-05 Thread James Stroud
[EMAIL PROTECTED] wrote: > I have a text source file of about 20.000 lines. >>From this file, I like to write the first 5 lines to a new file. Close > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files until processing of all 20.000 lines is > do

Re: Text processing and file creation

2007-09-05 Thread kyosohma
On Sep 5, 11:57 am, Bjoern Schliessmann wrote: > [EMAIL PROTECTED] wrote: > > I would use a counter in a for loop using the readline method to > > iterate over the 20,000 line file. > > file objects are iterables themselves, so there's no need to do that > by using a method. Very true! Darn it!

Re: Text processing and file creation

2007-09-05 Thread Shawn Milochik
On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines. > >From this file, I like to write the first 5 lines to a new file. Close > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files until proces

Re: Text processing and file creation

2007-09-05 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote: > I would use a counter in a for loop using the readline method to > iterate over the 20,000 line file. file objects are iterables themselves, so there's no need to do that by using a method. > Reset the counter every 5 lines/ iterations and close the file. I'd use a

Re: Text processing and file creation

2007-09-05 Thread Arnau Sanchez
[EMAIL PROTECTED] escribió: > I have a text source file of about 20.000 lines. >>From this file, I like to write the first 5 lines to a new file. Close > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files until processing of all 20.000 lines is

Re: Text processing and file creation

2007-09-05 Thread kyosohma
On Sep 5, 11:13 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines.>From this file, I like to > write the first 5 lines to a new file. Close > > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files

Text processing and file creation

2007-09-05 Thread [EMAIL PROTECTED]
I have a text source file of about 20.000 lines. >From this file, I like to write the first 5 lines to a new file. Close that file, grab the next 5 lines write these to a new file... grabbing 5 lines and creating new files until processing of all 20.000 lines is done. Is there an efficient way to d