I have a file called untitled.txt with the following lines:
Line 1: ATTCTGGA
Line 2: CGCCCGAATCCAGAACGCATTCCCATATTTCGGGACCACTGGCCTCCACGGTACGGACGTCAATCAAAT
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.
When I define "sp = 'ATTCTGGA'"
directly within the code, however, I get [6, 7, 26, 27]
, which is the correct answer.
Why does "sp = text.readline()"
not get the same result?
Because readline()
provides the whole line, including the trailing newline character. You should strip the trailing newline:
sp = text.readline().rstrip("\n")
p = text.readline().rstrip("\n")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.