[英]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.