Created
October 9, 2012 12:35
-
-
Save vkgtaro/3858552 to your computer and use it in GitHub Desktop.
CodeIQ 用問題
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
# -*- 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