Python return values?
The only thing I see wrong right now is you need a return
before testSomething()
on line 9.
brad
Updated on April 08, 2020Comments
-
brad about 4 years
How do I do this? Can I do this?
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()
needs to first make sure that a condition is true before it starts doing things. Because of encapsulation,aModuleEntryPoint
doesn't know how to check the condition, butaFunction()
has a sub-function calledtestSomething()
that does know how to check the condition.aModuleEntryPoint()
callsaFunction(theRightValue)
.Because
theRightValue
was passed toaFunction()
as an argument,aFunction()
callstestSomething()
.testSomething()
performs the logic test, and either returnsTrue
orFalse
.I need for
aModuleEntryPoint()
to know whattestSomething()
decided. I do not wantaModuleEntryPoint()
to know anything about howtestSomething()
came to its conclusion.It would actually be an accomplishment to post my actual source while removing other functions and what-not, so I had to setup the general gist like this.