[英]Python 2.7 Nested If-statement won't print string literal after printing array position
我有一个程序,它运行我正在分析的 A 型流感中蛋白质的氨基酸序列列表,并在我的 FASTA 文件中每个蛋白质的每个氨基酸序列的第 627 位找到氨基酸。
我的代码是这样工作的
with open(file, "r" ) as source:
for heading_and_lines in group_by_heading( source ):
heading= heading_and_lines[0]
lines= heading_and_lines[1:]
lines = ''.join(lines)
if lines[627-1] == 'K':
print "---------------MUTATION BELOW--------------"
print heading
print lines[627-1]
#print "-------------------------------------------"
print "end of file"
但是我的代码不是这样工作的
with open(file, "r" ) as source:
for heading_and_lines in group_by_heading( source ):
heading= heading_and_lines[0]
lines= heading_and_lines[1:]
lines = ''.join(lines)
if lines[627-1] == 'K':
print "---------------MUTATION BELOW--------------"
print heading
print lines[627-1]
print "-------------------------------------------"
print "end of file"
出于某种原因,打印我发现的突变下方的行会返回错误和意外缩进。 看到我想要每个突变下方的线,就像顶部的线一样,这样我就可以清楚地组织突变。 您认为下面的打印语句不起作用的任何原因?
对不起,如果这听起来很混乱,一如既往地感谢您的时间。
你的缩进是错误的,像这样缩进你的代码
with open(file, "r" ) as source:
for heading_and_lines in group_by_heading( source ):
heading= heading_and_lines[0]
lines= heading_and_lines[1:]
lines = ''.join(lines)
if lines[627-1] == 'K':
print "---------------MUTATION BELOW--------------"
print heading
print lines[627-1]
print "-------------------------------------------"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.