小编use*_*997的帖子

试图用语句和上下文管理器来理解python

我是新手,我只是想了解这个with陈述.我明白它应该替换try/ exceptblock.

现在假设我做了这样的事情:

try:
   name='rubicon'/2 # to raise an exception
except Exception as e:
   print "no not possible"
finally:
   print "Ok I caught you"
Run Code Online (Sandbox Code Playgroud)

如何用上下文管理器替换它?

python contextmanager

16
推荐指数
5
解决办法
9387
查看次数

标签 统计

contextmanager ×1

python ×1