![]() |
Understanding the concept ( Modules , imports ) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Understanding the concept ( Modules , imports ) (/thread-22734.html) |
Understanding the concept ( Modules , imports ) - erfanakbari1 - Nov-24-2019 Hey fellas . I've been trying to learn bunch of stuffs about modules and imports in Python , meanwhile I was stopped because of some codes in which I can't quite get the actual concept behind it's mechanism & how it works . This is the code import time from time import time as my_timer import random input("Please enter to start") wait_time = random.randint(1, 6) time.sleep(wait_time) start_time = my_timer() input("Press enter to stop") end_time = my_timer() print("Started at " + time.strftime("%X", time.localtime(start_time))) print("Ended at " + time.strftime("%X", time.localtime(end_time))) print("Your reaction time was {} seconds".format(end_time - start_time))I really appreciate if someone could just explain line by line of this code and what is really does for us . Cause I don't have any problems with running the code . I just want to comprehend the lines of code . Thanks RE: Understanding the concept ( Modules , imports ) - Larz60+ - Nov-25-2019 You should use a timer that doesn't lock the process. Sleep does this until complete. Here's a timer class that I wrote some time ago, by looking at the code you should be able to get some ideas on how to write interruptible timer routines: https://python-forum.io/Thread-Multi-threaded-Timer-Class Also, a good read is: https://pymotw.com/3/time/ |