Nov-22-2017, 08:37 AM
i want to call a function and assign the returned value to a variable, while this value is being tested. if a condition is met, then that value will be used in the clause the condition causes to be executed. if this were a simple if statement, then the function could be called before the if statement like:
temp = makeit() if testit(temp): sendit(temp)but here is the catch. one, the makeit() function is non-idempotent, which means i cannot make extra calls to it (it has side effects). and, two, this test is part of a sequence of elif statements where the previous tests must be done before this one. if things worked like they do in C then i would be inclined to do it like this:
if test1(): send1() elif test2(): send2() elif testit( (temp=makeit()) ): sendit(temp) elif test4(): send4() else: send5()but python does not like the assignment embedded in an expression, as is needed in the third test and code clause above. any suggestions?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.