Python进阶(上下文管理器与with语句)
/*上下文管理器必须有__enter__和__exit__方法*/ class MyResource: def __enter__(self): print('链接资源') return self /*__exit__返回True表示异常只会在__exit__中被捕获,不会继续传递到with语句的之外的except中,如果返回false,则会把异常也传递到except中*/ def __exit__(self,exc_type,exc_value,tb): if tb: print('链接进程异常') else: print('链接进程无异常') print('关闭资源链接') return False def query(self): print('query data') try: /*resource是上下文管理器__enter__返回的那个值*/ with MyResource() as resource: 1/0 resource.query() except Exception as ex: pass
https://edu.51cto.com/lecturer/11857712.html 星星课堂web前端系列课程
https://edu.51cto.com/course/25959.html js设计模式课程
https://edu.51cto.com/course/23133.html js进阶与组件化实战课程
https://edu.51cto.com/course/24757.html jquery课程
https://edu.51cto.com/course/22392.html js基础与入门课程
https://edu.51cto.com/course/26063.html vue零基础入门课程
https://edu.51cto.com/course/22393.html xhtml与css基础入门课程