-
-
Save MelanX/8952e70d52fb17097f8df097cbd96c79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
class Timer(object): | |
"""A simple timer class""" | |
def __init__(self): | |
pass | |
def start(self): | |
"""Starts the timer""" | |
self.start = datetime.datetime.now() | |
return self.start | |
def stop(self, message="Total: "): | |
"""Stops the timer. Returns the time elapsed""" | |
self.stop = datetime.datetime.now() | |
return message + str(self.stop - self.start) | |
def reset(self): | |
"""Resets the timer.""" | |
del self.start | |
del self.stop | |
return str("Stopwatch reset.") | |
def now(self, message="Now: "): | |
"""Returns the current time with a message""" | |
return message + str(datetime.datetime.now()) | |
def elapsed(self, message="Elapsed: "): | |
"""Time elapsed since start was called""" | |
return message + str(datetime.datetime.now() - self.start) | |
def split(self, message="Split started at: "): | |
"""Start a split timer""" | |
self.split_start = datetime.datetime.now() | |
return message + str(self.split_start) | |
def unsplit(self, message="Unsplit: "): | |
"""Stops a split. Returns the time elapsed since split was called""" | |
return message + str(datetime.datetime.now() - self.split_start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am brand new to coding, so this might be a stupid question. When I execute your code it displays the run file but not seeing the actual timer. What am I missing?