A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/353114.html below:

Printing w/o newlines inside loops

Printing w/o newlines inside loops - odd behaviorJeffrey E. Forcier jforcier at strozllc.com
Tue Sep 13 17:54:12 EDT 2005
This is a difficult issue to search for, and Googling (and reviewing
the pertinent Python docs) has not found me anything useful. It's also
not a super important issue, but regardless of whether it's avoidable,
I still want to know what the heck is going on.

Doing multiple print statements inside a for loop, using the 'comma at
the end eats the newline' variant, results in zero output until the
loop completes its entire iteration.

def test():
   print "testing:",
   for x in range(10):
       time.sleep(1)
       print ".",
   print "done."

Executing test() results in the behavior described above. If one
removes the commas after the first two print statements, it behaves
normally, with "testing" showing up right away, then a period on each
newline every second until the end.

I've tried various things--os.system('sleep 1') instead of
time.sleep(1), sys.stdout.write() instead of print-with-a-comma, and
other equally silly tactics, to no avail.

What's going on here?

Thanks,
Jeff


More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4