Skip to content

Instantly share code, notes, and snippets.

@CodeIQ
Forked from vkgtaro/clock.py
Created October 10, 2012 02:17
Show Gist options
  • Save CodeIQ/3862766 to your computer and use it in GitHub Desktop.
Save CodeIQ/3862766 to your computer and use it in GitHub Desktop.
CodeIQ 用問題
# -*- coding: utf-8 -*-
import sys
import time
import datetime
class Observable():
pass
class Tick(Observable):
def start (self):
while True:
now = datetime.datetime.now()
self.changed()
self.notify_observers([now.hour, now.minute, now.second])
time.sleep( 1.0 - (datetime.datetime.now().microsecond / 1000000.0) )
class TextClock():
def update(self, time):
sys.stdout.write( "\r%02d:%02d:%02d" % tuple(time) )
sys.stdout.flush()
if __name__ == '__main__':
tick = Tick()
tick.add_observer( TextClock() )
tick.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment