[Tutor] Confirmation if command worked

Christian Witts cwitts at compuscan.co.za
Thu Aug 25 10:37:21 CEST 2011

On 2011/08/25 10:19 AM, Alan Gauld wrote:
> On 25/08/11 07:25, Christian Witts wrote:
>> Once you call child.close() the exit and signal status will be stored in
>> .exitstatus and .signalstatus, for a normal exit of the program
>> .exitstatus will store the return code from SCP as per [1] [2] [3] and
>> .signalstatus will be None.  If SCP was terminated with a signal then
>> .exitstatus will be None and .signalstatus will contain the signal
>> value.  Info found in the docs [4].
>>      data = child.read()
>>      child.close()
>>      if child.exitstatus and child.exitstatus == 0:
>>          success = True
>>      else:
>>          success = False
> Won't that if statement always evaluate to false?
> If exitstatus is 0 the first part of the and will be false and so the 
> entire and expression is false.
> If exitstatus is not 0 then the second part of the and will be false 
> and again the and result will be false.
> Did you mean to use exitstatus for both tests?
> Or am I missing something subtle here?

Good catch, it should be `if child.exitstatus != None and 
child.exitstatus == 0:` or removing the first part entirely.  The 
zero-evaluating-as-False has bitten me before and for some reason I 
still on occasion forget it even though I use it often for data extracts.


Christian Witts
Python Developer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110825/fc9a959a/attachment.html>

More information about the Tutor mailing list