Python : Delay with time.sleep() function example
It has been a while since I look at Python code. Need to read up a legacy code left by the previous developer and do some minor adjustment to the existing source code.
Basic stuff, nothing to deep or complicated. Just need to introduce delay into the code.
Here is an example on how to use Python's time module to delay execution.
import time
def main():
print("The time is : " + time.strftime("%c"))
time.sleep(10) # delay for 10 seconds
print("After 10 seconds, the time is now : " + time.strftime("%c"))
if __name__ == '__main__':
main()
Sample output :
The time is : Fri Oct 23 09:51:28 2015
After 10 seconds, the time is now : Fri Oct 23 09:51:38 2015
Reference :
See also : Golang : Call a function after some delay(time.Sleep and Tick)
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+10.3k Golang : How to profile or log time spend on execution?
+8.1k Findstr command the Grep equivalent for Windows
+13.3k Golang : How to calculate the distance between two coordinates using Haversine formula
+9.5k Golang : Timeout example
+5.7k Swift : Get substring with rangeOfString() function example
+8k Swift : Convert (cast) String to Float
+17.5k Golang : Check if IP address is version 4 or 6
+10k Golang : Translate language with language package example
+8.9k Golang : Take screen shot of browser with JQuery example
+9.2k Golang : Simple histogram example
+5k Nginx and PageSpeed build from source CentOS example
+7.5k Linux : How to fix Brother HL-1110 printing blank page problem