[Tutor] Printing time without "if" statement

Elisha Rosensweig benshafat at gmail.com
Mon Mar 8 05:38:49 CET 2010


Hi,

I have an event-based simulator written in Python (of course). It takes a
while to run, and I want to have messages printed every so often to the
screen, indicating the simulation time that has passed. Currently, every
event that occurs follows the following code snippet:

# initilize
printstep = 10
nextprint = 10

# for each event
if current_time > nextprint:
                print 'time past: ' + str(nextprint)
                nextprint += printstep

This seems stupid to me - why should I have to check each round if the time
has been passed? I was thinking that there might be a simpler way, using
threading, but I have zero experience with threading, so need your help. The
idea was to have a simple thread that waited X time (CPU cycles, say) and
then read the "current_time" variable and printed it.

Any simple (simpler?) solutions to this?

Thanks

Elisha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100307/5230858a/attachment.html>


More information about the Tutor mailing list