[python]An example of with_as

2022-12-5 写技术

class newc:
    def __enter__(self):
        print("enter of newc\n")
        return self

    def __exit__(self,type,value,trace):
        print("exit of newc\n")
        print("type:", type)
        print("value:", value)
        print("trace:", trace)

    def fun(self):
        print("fun in newc:\n")

with newc() as ppt:
    ppt.fun()
    print("exit\n")

标签: python

发表评论:

Powered by anycle 湘ICP备15001973号-1