[Tutor] endless processing through for loop

John Fouhy john at fouhy.net
Mon Jun 23 03:07:54 CEST 2008


On 23/06/2008, Dinesh B Vadhia <dineshbvadhia at hotmail.com> wrote:
> I have a program with 2 for loops like this (in pseudocode):
>
> fw = open(newLine.txt, 'w')
> for i in xrange(0, 700,000, 1):
>     read a file fname from folder
>     for line in open(fname, 'r'):
>         do some simple string processing on line
>         fw.write(newline)
> fw.close()
>
> That's it.  Very simple but after i reaches about 550,000 the program begins
> to crawl.  As an example, the loops to 550,000 takes about an hour.  From
> 550,000 to 580,000 takes an additional 4 hours.
>
> Any ideas about what could be going on?

What happens if you reverse the loop?

i.e. change to:

for i in xrange(699999, -1, -1):

-- 
John.


More information about the Tutor mailing list