From: Mark Day Date: 2007-05-10T09:49:30+09:00 Subject: Re: Ruby Performance - LOW ? On May 9, 2007, at 5:37 PM, Alex Young wrote: >> Let's say we're doing some intense calculations >> and we want to show a simple progress indicator: >> 40.times { >> print "." >> >> time_consuming_routine >> } >> puts "\nFinished." >> And the output is >> ........................................ >> Finished. > >> Can you figure out how to do this trivial task >> in Python? > Not hard. Trivial, in fact. > > for i in range(0,40): You don't actually need the "0," part there. "for i in range(40):" would be more typical. > sys.stdout.write('.') > time_consuming_routine() > > sys.stdout.write("\nFinished.") Note that due to buffering of standard output, both snippets may not actually produce any output until the final puts/print. In the Ruby script, add "$stdout.flush" after the print. In Python, add "sys.stdout.flush()" after the sys.stdout.write. -Mark