<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br>if line.strip()<br><br></div>Is that stripping the line of white space at the same time that it is testing it? <div class="gmail_extra">
<div><div class="h5">
<br></div></div></div></div></blockquote><div><br></div><div><br></div><div>Two features about Python:</div><div><br></div><div>1. Strings are immutable, so the above is computing what a whitespace-stripped line would look like. So that means that 'line.strip()' is doing just a computation: it's not mutating the original line, but computing a new string that has its leading and trailing whitespace stripped away.</div>
<div><br></div><div><br></div><div>2. Empty strings are treated as false values. I'm not happy with how loose Python treats truth, and would rather prefer:</div><div><br></div><div> if line.strip() != "": ...</div>
<div><br></div><div>so that the thing being tested is explicitly either True or False. I like my truth to be black and white, but I suppose I'll have to grimace and bear the fuzziness. :P</div><div><br></div><div><br>
</div><div>Together, we see those two features allow us to look at the test in the Python code:</div><div><br></div><div> if line.strip(): ...</div><div><br></div><div>and rephrase it in English as:</div><div><br></div>
<div> "If the line consists of at least one non-whitespace character: ..."</div></div></div></div>