1
我有下面的代码现在添加with语句以非详细模式在织物(Python)的
if (verbose):
with hide('running', 'stdout', 'stderr'):
line 1
line 2
else:
line 1
line 2
有什么办法避免线路1和2号线的重复?
我有下面的代码现在添加with语句以非详细模式在织物(Python)的
if (verbose):
with hide('running', 'stdout', 'stderr'):
line 1
line 2
else:
line 1
line 2
有什么办法避免线路1和2号线的重复?
def dothisstuff():
line 1
line 2
if (verbose):
with hide('running', 'stdout', 'stderr'):
dothisstuff()
else:
dothisstuff()
虽然这可能是矫枉过正只有2重复2行。但我认为它是更多的2行:)
谢谢。有时我会在寻找复杂解决方案时错过显而易见的东西:)。 – bonzi 2011-04-08 12:51:40
做一个函数? – 2011-04-08 12:13:48