我該怎麼做? 罐我這樣做?Python返回值?
def aFunction(argument):
def testSomething():
if thisValue == 'whatItShouldBe':
return True
else:
return False
if argument == 'theRightValue': # this is actually a switch using elif's in my code
testSomething()
else:
return False
def aModuleEntryPoint():
if aFunction(theRightValue) == True:
doMoreStuff()
else:
complain()
aModuleEntryPoint()
aModuleEntryPoint()
在開始做事之前需要先確定一個條件是真的。由於封裝,aModuleEntryPoint
不知道如何檢查條件,但aFunction()
有一個名爲testSomething()
的子功能,它知道如何檢查條件。 aModuleEntryPoint()
來電aFunction(theRightValue)
。
因爲theRightValue
作爲參數傳遞給aFunction()
,所以aFunction()
調用testSomething()
。 testSomething()
執行邏輯測試,並返回True
或False
。
我需要aModuleEntryPoint()
知道什麼testSomething()
決定。我不想aModuleEntryPoint()
知道如何testSomething()
得出結論。
這實際上是一個成就,發佈我的實際來源,同時刪除其他功能和什麼,所以我不得不這樣設置一般的要點。
謝謝@Eimantas,這會讓我的頭部受傷更少:) – 2011-04-10 06:07:49