YMXC's 树洞

上下文管理器

在Python中想要使用with的建议做法是使用@contextmanager装饰器,由python提供但需要导入 @contextmanager def fun(args): pass yeild result with fun(args) as f: pass

羽墨星辰 发布于 2026-01-06