I want to do something:

chris liechti cliechti at mails.ch
Sat Jul 28 10:52:55 EDT 2001


[posted and mailed]

"Jeremy Moles" <xione at bellsouth.net> wrote in
news:jYy87.177$vM1.2880 at e3500-atl1.usenetserver.com: 
> Basically, what this code does is get my IP address and upload it to my
> webserver - since my IP is dynamic, and I never quite know what it is
> when I leave this house.
> 
> But anyways - how can I do this - say - every minute or so? Could I:
> 
> import time
> 
> while(time.time()%60==0):
>     do_my_function()
> 
this will not do what you want.. surround the modulo expression with 
int(...) otherwise it chances are small that it will be zero (the 
probability for the milliseconds beeing exacly zero are 1/1000 and % with 
floats returns a float reminder). also this while loop would exit when it 
sould do the function call but call it in a loop when you want to wait (and 
does this with 100% CPU load)...

i would do it with sleep:
-------
import time

while 1:
    	do_my_function()     	#upload file
    	time.sleep(600)    	#wait ten minits
-------
i also think that ten minits or some hours are enough. usually the IP is 
valid for some longer time. i now get the same IP assigned (DHCP) for over 
one month and i switch off the pc every night.

chris <cliechti at mails.ch>




More information about the Python-list mailing list