0
我有這樣的:幾個「與....爲VAR1」符合條件
if condition1:
with func1() as var1:
with func2() as var2:
# a lot of stuff here
else:
with func2() as var2:
# the exact same stuff as above
有沒有辦法做這樣的事情?
if condition1:
with func1() as var1:
????
# func2() is called anyway
with func2() as var2:
# a lot of stuff here
與此相反:
def some_stuff():
# a lof of stuff
if condition1:
with func1() as var1:
with func2() as var2:
some_stuff()
else:
with func2() as var2:
some_stuff()
正如你所看到的,func2()
無論如何調用,通過func1()
只有當condtion是真實的。
您能否解釋一下「我想要一個預處理器」的說法? –
@BhargavRao,更新。 – Kurama
不會把'func2()作爲var2:'if else'之外的塊按預期工作嗎? –