Skip to content

Instantly share code, notes, and snippets.

@vkgtaro
Created October 9, 2012 12:35
Show Gist options
  • Save vkgtaro/3858552 to your computer and use it in GitHub Desktop.
Save vkgtaro/3858552 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