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
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
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
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
[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
> 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
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
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
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
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
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
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
[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
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!
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
[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
[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
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
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
19 matches
Mail list logo