7
如果我有這樣的結構:什麼是檢查多個變量不是無的最pythonic方法?
def foo():
a=None
b=None
c=None
#...loop over a config file or command line options...
if a is not None and b is not None and c is not None:
doSomething(a,b,c)
else:
print "A config parameter is missing..."
什麼是蟒蛇的首選語法檢查所有變量都設置爲有用的值?這是我寫的,還是另一種更好的方式?
這是不同於這個問題: not None test in Python ...我正在尋找首選的方法來檢查,如果許多條件不是無。我輸入的選項看起來非常長且非pythonic。
[Python中不無測試(可能的重複http://stackoverflow.com/問題/ 3965104/not-none-test-in-python) – schwobaseggl
我正在檢查四個變量,並且認爲你發佈的顯而易見的解決方案不是很pythonic。我很遺憾,必須從缺乏答案中得出結論,似乎並沒有一個「更好的」方法。 – wedi
@schwobaseggl:不,這不是重複的,因爲問題不在於如何檢查無。這是關於如何讓它在檢查多個變量時「看起來更加pythonic」,而不是更多,以糾正Daniel Roseman提出的解決方案。 – wedi