About the with statement

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 the statement within the next method __enter__ a double and __exit__ the first execution __enter__ doing operations and then execute __exit__ exit

 

Guess you like

Origin www.cnblogs.com/a438842265/p/12118439.html