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
+21.3k SSL : How to check if current certificate is sha1 or sha2
+36.1k Golang : Convert(cast) int64 to string
+14.4k Golang : Get URI segments by number and assign as variable example
+11.1k Golang : Characters limiter example
+7.1k Golang : Accessing dataframe-go element by row, column and name example
+9.1k Golang : Scramble and unscramble text message by randomly replacing words
+10.7k Golang : Replace a parameter's value inside a configuration file example
+22.4k Golang : Round float to precision example
+13.1k Golang : Read from buffered reader until specific number of bytes
+4.8k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+47.6k Golang : How to convert JSON string to map and slice
+9.5k Golang : Load ASN1 encoded DSA public key PEM file example