Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我现在有以下代码
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 行 :)