Skip to content

Instantly share code, notes, and snippets.

@puhitaku puhitaku/seishin.py
Created Aug 10, 2019

Embed
What would you like to do?
精神と時の部屋
class 部屋:
def __init__(self):
self.elapsed = 0
self.delta = 1000
def 時を進める(self):
self.elapsed += self.delta
def 精神と時の部屋にする(self):
class Temp:
def __enter__(_):
print('精神と時の部屋に入ります')
self.delta = 100
return self
def __exit__(_, e_typ, e_val, e_trace):
print('精神と時の部屋から出ます')
self.delta = 1000
return Temp()
room = 部屋()
for _ in range(10):
print(f'現在の経過ミリ秒は{room.elapsed}')
room.時を進める()
print()
with room.精神と時の部屋にする() as room:
for _ in range(10):
print(f'現在の経過ミリ秒は{room.elapsed}')
room.時を進める()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.