Created
July 28, 2014 18:39
-
-
Save damoxc/096363ec0a819b35317c to your computer and use it in GitHub Desktop.
A simple clock in Py3
This file contains hidden or 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
#!/usr/bin/python3 | |
import sys | |
import time | |
import datetime | |
BS_CHAR = '\u0008' | |
DATE_FMT = '%Y-%m-%d %H:%M:%S' | |
def clock(): | |
while True: | |
now = datetime.datetime.now() | |
sys.stdout.write(BS_CHAR * 40) | |
sys.stdout.write(now.strftime(DATE_FMT)) | |
sys.stdout.flush() | |
time.sleep(1) # sleep for 1 second | |
def main(): | |
try: | |
clock() | |
except KeyboardInterrupt: | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment