> Danny Yoo wrote:
> >
> > file('filename.txt').readlines()[-1]
> Not to hijack the thread, but what stops you from just putting a
> file.close() after your example line?
> >>> Which file should file.close() close? The problem is that we don't
> >>> have a handle on the particular fi
Oops, my mistake, I did read your code, as well as all the others and I had your code mixed with another submission. In that case, excellent contribution =DOn 10/19/06,
Luke Paireepinart <[EMAIL PROTECTED]> wrote:
Chris Hengge wrote:> More on that.. some of the file I work with are thousands of li
Chris Hengge wrote:
> More on that.. some of the file I work with are thousands of lines
> long... one is even 10's of thousands.. so reading the entire thing
> into ram is MUCH faster then reading line by line with the filestream
> open.
Did you look at my code?
It doesn't read the whole thing
More on that.. some of the file I work with are thousands of lines long... one is even 10's of thousands.. so reading the entire thing into ram is MUCH faster then reading line by line with the filestream open.
On 10/19/06, Chris Hengge <[EMAIL PROTECTED]> wrote:
I dont care for slow... I dont use
I dont care for slow... I dont use computers with less then 1gb of ram.. (all my systems have 2gb), I hate to wait... =D If I've got memory to use, I intend to use it!As for reading 100 20mb files, I'd do one at a time, then dump the variable storing the data, or reset/re-use. Just my take though.
Chris Hengge wrote:
> I thought my solution was the easiest.. but I guess everyone skipped it =P
No, we didn't skip it,
but as we're all programmers here, we showed alternate ways that it
could be done.
Your post is the one that sparked the whole 'garbage collection' thing,
you'll notice.
Now, I
I thought my solution was the easiest.. but I guess everyone skipped it =POn 10/19/06, Kent Johnson <[EMAIL PROTECTED]
> wrote:Danny Yoo wrote:>> file('filename.txt').readlines()[-1]
Not to hijack the thread, but what stops you from just putting a file.close() after your example line?>
Danny Yoo wrote:
>
> file('filename.txt').readlines()[-1]
Not to hijack the thread, but what stops you from just putting a
file.close() after your example line?
>>> Which file should file.close() close? The problem is that we don't
>>> have a handle on the particular file we want
Danny This is a very clean way to get the last line.
Thanks.
Regards,
Asrarahmed
On 10/19/06, Danny Yoo <[EMAIL PROTECTED]> wrote:
> first count the number of lines in the file by using a loop. Use a> second loop and when teh counter reaches the num_of_lines values: take
> the line.>> Is th
Very informative and creative reply! Thanks for sharing :]On 10/19/06, Danny Yoo <[EMAIL PROTECTED]
> wrote:>> >> file('filename.txt').readlines()[-1]>>
>> > Not to hijack the thread, but what stops you from just putting a>> > file.close() after your example line? Which file should file.close()
>> >> file('filename.txt').readlines()[-1]
>>
>> > Not to hijack the thread, but what stops you from just putting a
>> > file.close() after your example line?
>>
>> Which file should file.close() close? The problem is that we don't
>> have a handle on the particular file we want to close off
> This works as well
>
> file('filename.txt').readlines()[-1]
>
> Some will say that this is no good because the file is still open.
> However I've been told that when the object is cleaned the file is
> closed so it should be fine.
It matters in an implementation like Jython, which depends on t
Oh wow.. I totally missed that... nevermind.. ignore that question =DOn 10/19/06, Danny Yoo <[EMAIL PROTECTED]
> wrote:>> file('filename.txt').readlines()[-1]> Not to hijack the thread, but what stops you from just putting a
> file.close() after your example line?Which file should file.close() clos
>> file('filename.txt').readlines()[-1]
> Not to hijack the thread, but what stops you from just putting a
> file.close() after your example line?
Which file should file.close() close? The problem is that we don't have a
handle on the particular file we want to close off.
___
> first count the number of lines in the file by using a loop. Use a
> second loop and when teh counter reaches the num_of_lines values: take
> the line.
>
> Is there any other way to do it??
Yes, there's a way to do it in one pass: you can keep track of the very
last line you've read from the
Chris Hengge wrote:
> Not to hijack the thread, but what stops you from just putting a
> file.close()
> after your example line?
Because file is a class.
file(filename) creates a file object, but he's not saving the object to
a variable, so its lost. file.close() takes a file object as a
parameter
Not to hijack the thread, but what stops you from just putting a file.close() after your example line?On 10/19/06, Chad Crabtree <
[EMAIL PROTECTED]> wrote:file('filename.txt').readlines()[-1]
Some will say that this is no good because the file is still open. However I've been told that when the o
On 10/19/06, Chris Hengge <[EMAIL PROTECTED]> wrote:
I'd personally do something like this. file = open(myfile, 'r')fileContents = file.readlines() # read the entire document into memory for speed.file.close()print fileContents[-1] # This is the last line.
This works as wellfile('filename.txt').rea
Asrarahmed Kadri said unto the world upon 19/10/06 12:55 PM:
> My algorithm is like this:
> first count the number of lines in the file by using a loop.
> Use a second loop and when teh counter reaches the num_of_lines values:
> take
> the line.
>
> Is there any other way to do it??
>
>
>
> On
I'd personally do something like this. file = open(myfile, 'r')fileContents = file.readlines() # read the entire document into memory for speed.file.close()print fileContents[-1] # This is the last line.
On 10/19/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
My algorithm is like this:
first count
My algorithm is like this:
first count the number of lines in the file by using a loop.
Use a second loop and when teh counter reaches the num_of_lines values: take the line.
Is there any other way to do it??
On 10/19/06, Danny Yoo <[EMAIL PROTECTED]> wrote:
On Thu, 19 Oct 2006, Asrarahmed Kadr
On Thu, 19 Oct 2006, Asrarahmed Kadri wrote:
> I want to extract the last line of the text file. Any idea ???
Hi Asrarahmed,
Ok, so what part do you get stuck on when you try to do this? That is,
what sort of things do you already know how to do with files?
__
Hi Folks,
I want to extract the last line of the text file. Any idea ???
Thanks,
Regards,
Asrarahmed-- To HIM you shall return.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
23 matches
Mail list logo