str.endwith() return false in valid check
<p><strong>I don't need alternate solution.</strong>  </p>

<p>I'm using Python 2.5.4 and want know why this happens.</p>

<p>I write source parser for makefiles.</p>

<pre><code>ff = open("module.mk")
f = ff.readlines()
ff.close()
for i in f:
 if ".o \\" in i[-5:]:
  print "Is %s for str: %s" %(i.endswith('.o \\'), i)
</code></pre>

<p>I got:</p>

<pre class="lang-none prettyprint-override"><code>Is False for str:       bitmap.o \
</code></pre>

<p>And so for every check.</p>

<p>You can get module.mk from <a href="https://github.com/scummvm/scummvm/blob/master/engines/access/module.mk" rel="nofollow">github</a></p>

<p>When you use <code>.readlines()</code> it includes the newline character in the line, CR-LF in this case.</p>

<p>You need to remove that newline before checking <code>.endswith()</code> as such:</p>

<pre><code>with open("module.mk") as data:    
    for i in data.readlines():
        if ".o \\" in i[-5:]:
            print "Is %s for str: %s" %(i.strip().endswith('.o \\'), i)
</code></pre>

<p>Note: The <code>.readlines()</code> call isn't needed here, I'm just keeping it in so that the behaviour remains the same as OP's code.</p>

python parsing windows-xp