示例:

class Foo:
    def __enter__(self):
        print("Foo: __enter__")

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("Foo: __exit__")


foo = Foo()

with foo:
    pass

# Foo: __enter__
# Foo: __exit__

待续。。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案