[Tutor] Confirmation if command worked

Steven D'Aprano steve at pearwood.info
Thu Aug 25 14:18:41 CEST 2011

Christian Witts wrote:

>     if child.exitstatus and child.exitstatus == 0:
>         success = True
>     else:
>         success = False

There is never any need to write Python code that looks like that. (Or 
in any other language I'm familiar with either.) Anything of the form:

if some_condition:
     flag = True
     flag = False

is better written as:

flag = some_condition

In the above example, you should write:

success = child.exitstatus and child.exitstatus == 0

except that I think you have the condition wrong... if exitstatus is 
zero, you get False and True => False, but if exitstatus is non-zero, 
you get True and False => False. So you will always get success = False.


More information about the Tutor mailing list