首页 > 其他 > 详细

关于 with 语句

时间:2019-12-30 11:19:25      阅读:91      评论:0      收藏:0      [点我收藏+]
class C(object):
    def __enter__(self):
        print(‘jinru‘)
        return self


    def __exit__(self, exc_type, exc_val, exc_tb):
        print(‘chuqu‘)


with C() as f:
    print(f)
    print(123)

with语句  在内部有一个 __enter__  和  __exit__  的双下方法 先执行 __enter__ 在做操作 再执行__exit__   退出

 

关于 with 语句

原文:https://www.cnblogs.com/a438842265/p/12118439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!