Python Forum
Understanding the concept ( Modules , imports )
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understanding the concept ( Modules , imports )
#1
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
Reply
#2
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-thr...imer-Class
Also, a good read is: https://pymotw.com/3/time/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best programming practice for imports Curbie 8 1,572 Oct-16-2024, 02:20 AM
Last Post: Curbie
  Sudden Extremely Slow / Failed Python Imports bmccollum 1 1,055 Aug-20-2024, 02:09 PM
Last Post: DeaD_EyE
  Guidance for the basic concept send/receive a heartbeat signal StefanL38 1 1,583 Jun-09-2024, 05:31 PM
Last Post: Gribouillis
  Imports that work with Python 3.8 fail with 3.9 and 3.10 4slam 1 3,436 Mar-11-2022, 01:50 PM
Last Post: snippsat
  Imports in my first package cuppajoeman 1 2,481 Jun-28-2021, 09:06 AM
Last Post: snippsat
  script with imports works but pytest gives "ModuleNotFoundError"? Hpao 0 2,098 Jun-27-2021, 08:30 PM
Last Post: Hpao
  How we prune Alphabeta Tree Node Using BST concept Anldra12 4 3,156 May-18-2021, 09:17 AM
Last Post: Anldra12
  Help wanted with python imports petros21 3 3,477 Apr-07-2021, 07:16 PM
Last Post: snippsat
Question How to include Modules not found (conditional imports) in my setup.py when I want to cff 0 4,745 Mar-17-2021, 11:57 AM
Last Post: cff
  threading across imports Nickd12 2 2,954 Nov-09-2020, 01:59 AM
Last Post: Nickd12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020