<div class="gmail_quote">On Mon, Oct 5, 2009 at 3:37 PM, Sander Sweers <span dir="ltr"><<a href="mailto:sander.sweers@gmail.com">sander.sweers@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Thanks Wesly/Vern for the replies.<br>
<div class="im"><br>
On Mon, 2009-10-05 at 21:56 +0200, Luke Paireepinart wrote:<br>
> if not n == 0<br>
><br>
</div><div class="im">> if b == True can be written as if b.<br>
><br>
><br>
> However,<br>
> if not n == 0 can be written as if n != 0 but NOT as if n.<br>
> The reason why is that 0 is not equivalent to False even though it<br>
> evaluates to False.<br>
> So<br>
> if not n:<br>
> would be true for n = 0 and for n = "" and for n = None<br>
> but<br>
> if n != 0:<br>
> would be true for n = "" and n = None but not n = 0.<br>
<br>
</div>Ah, have not thought about this one. In this case it checks the return<br>
code of a subprocess command which if not zero means build failure. I am<br>
leaving these as they are because in my opinion "if not returncode == 0"<br>
shows clearer what is going on than "if returncode".<br></blockquote><div><br></div><div>If it's checking the returncode against a value, Vern makes a good point:</div><div><br></div><div>if returncode != 0 makes a whole lot more sense than "if not returncode == 0"</div>
<div><br></div><div>Though when dealing with an integer return code, doesn't it make more sense to use the "is" operator?</div><div><br></div><div>if returncode is 0:</div><div> #do something</div><div><br>
</div><div>if returncode is not 0:</div><div> #do something</div><div><br></div><div>-Wayne</div></div>