「Python初心者」contextlibモジュールを利用する参考ソースコード

例1:
with open(“filename”) as f:
f.read()

例2
class closing(object):
def __init__(self, thing):
self.thing = thing
def __enter__(self):
return self.thing
def __exit__(self, *exc_info):
self.thing.close()

Comments are closed.