Why isn't readline() working properly?
<p>I have a file called untitled.txt with the following lines:</p>

<pre><code>Line 1: ATTCTGGA

Line 2: CGCCCGAATCCAGAACGCATTCCCATATTTCGGGACCACTGGCCTCCACGGTACGGACGTCAATCAAAT
</code></pre>

<p>When I enter code for finding the positions where sp (line 1) appears in p (line 2) with a maximum of d errors, I get the output [27], which is only one of the correct positions.</p>

<p>code using only readline():
<a href="https://i.stack.imgur.com/CO5EF.png" rel="nofollow"><img src="https://i.stack.imgur.com/CO5EF.png" alt="enter image description here"></a></p>

<p>When I define <code>"sp = 'ATTCTGGA'"</code> directly within the code, however, I get <code>[6, 7, 26, 27]</code>, which is the correct answer.</p>

<p><a href="https://i.stack.imgur.com/LLtEX.png" rel="nofollow"><img src="https://i.stack.imgur.com/LLtEX.png" alt="enter image description here"></a></p>

<p>Why does <code>"sp = text.readline()"</code> not get the same result?</p>

<p>Because <code>readline()</code> provides the whole line, including the trailing newline character.  You should strip the trailing newline:</p>

<pre><code>sp = text.readline().rstrip("\n") 
p = text.readline().rstrip("\n")
</code></pre>

python python-3.x bioinformatics jupyter jupyter-notebook