2010-07-12 :-)
_ 朝ッ
0520 起床
_ 仕事
0830 出勤
_ ,
そおいえばまだ長谷川さん(仮名)に挨拶してない
_ 居室に閉じ込められた
入室退室時に ID カードを出入り口に設置されているカードリーダーにかざして、入室と退室が必ず対(つい)になるようにしておく必要があるんだが
- 退室しようとしてかざす
- ( 扉の鍵が開く )
- 忘れ物を取りに自席へ戻る
- ( 扉閉まる )
- もう開かない
鍵を持ってるが外に出られないという事態に陥った。他の誰かに開けてもらうしかない。
追記: と思ったらリセットする方法があるらしい。ってそれ 3 年前にも聞いたな
_ [Python][デザインパターン][Singleton]Python でデザインパターン - Singleton
Ruby で書いたアレ[ 20090507#p05 ]を 1 対 1 で書き換える。
こんなんでいいのか?
#!/usr/bin/python
# -*- coding:utf8 -*-
# ruby コードを書き換える
# http://www.area51.gr.jp/~rin/diary/?date=20090507#p05
#
class Singleton:
__instance = None
def get_instance(self):
if Singleton.__instance != None:
return Singleton.__instance
else:
Singleton.__instance = 0
return Singleton.__instance
print Singleton().get_instance()
ActiveState Code にこんなのがあった。ディクショナリを使ってる。
class Singleton(type):
def __init__(self, *args):
type.__init__(self, *args)
self._instances = {}
def __call__(self, *args):
if not args in self._instances:
self._instances[args] = type.__call__(self, *args)
return self._instances[args]
class Test:
__metaclass__ = Singleton
def __init__(self, *args):
pass
ta1, ta2 = Test(), Test()
assert ta1 is ta2
tb1, tb2 = Test(5), Test(5)
assert tb1 is tb2
assert tb1 is not tb2
_ [Python][デザインパターン][Command]Python でデザインパターン - Command
書き換え[ 20090507#p06 ]
#!/usr/bin/python
# -*- coding:utf8 -*-
# ruby コードを書き換える
# http://www.area51.gr.jp/~rin/diary/?date=20090507#p06
#
class Command:
def execute(self):
return
class Command1(Command):
def execute(self):
print "皇帝陛下ですね?"
class Command2(Command):
def execute(self):
print "そうだ。"
class Command3(Command):
def execute(self):
print "妹ロックブーケのカタキです。殺らせていただきます。"
class Noel:
def __init__(self):
self.slot = []
def add(self, command):
self.slot.append(command)
def run(self):
for c in self.slot:
c.execute()
def main():
noel = Noel()
noel.add(Command1())
noel.add(Command2())
noel.add(Command3())
noel.run()
main()
[ツッコミを入れる]



