在Fabric(Python)中以简洁模式添加with语句
我现在有以下代码:
if (verbose):
with hide('running', 'stdout', 'stderr'):
line 1
line 2
else:
line 1
line 2
有没有什么办法可以避免第1行和第2行的重复呢?
1 个回答
1
def dothisstuff():
line 1
line 2
if (verbose):
with hide('running', 'stdout', 'stderr'):
dothisstuff()
else:
dothisstuff()
虽然对于只有两行重复两次来说,这可能有点多余。不过我猜这应该不止两行吧 :)