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
+12.5k Golang : zlib compress file example
+18.5k Unmarshal/Load CSV record into struct in Go
+7.6k Golang : Get today's weekday name and calculate target day distance example
+31.2k Golang : Get local IP and MAC address
+10.4k Golang : How to delete element(data) from map ?
+5.8k Golang : Missing Subversion command
+14.1k Golang : How to shuffle elements in array or slice?
+6.2k PHP : Proper way to get UTF-8 character or string length
+8.8k Golang : Inject/embed Javascript before sending out to browser example
+19.5k Golang : Archive directory with tar and gzip
+22.7k Golang : Gorilla mux routing example
+8.6k Golang : Random integer with rand.Seed() within a given range