我正在进行一个相当简单的程序,将一个给定的非编码链DNA转换为所有它的对应链(编码、mRNA、tRNA和氨基酸链)。
但是,当我试图分割字符串时,我会得到一个IndexError:
mRNA_parts = mRNA.split(' ')
print mRNA_parts, # using for debugging purposes
for base in mRNA_parts:
print base # again, for debugging
partA = base[0]
partB = base[1]
partC = base[2]
my_acid = (amino_acids[partA][partB][partC]) + ' '
# 'amino_acids' is a 3D (thrice-nested) dictionary with the corresponding parts of mRNA to convert to the amino acid chain.
# part of the nested dictionary: amino_acids = {'U': {'U': {'U': 'Phe'}}}. This is only one part (out of 64) of it.
# Thus, if the mRNA section was 'UUU', the amino acid would be 'Phe '.
acid_strand += my_acid这是我得到的错误:
['GAU', '']
GAU
Traceback (most recent call last):
File "D:\my_stuff\Google Drive\documents\SCHOOL\Programming\Python\DNA to RNA Converter.py", line 83, in <module>
main()
File "D:\my_stuff\Google Drive\documents\SCHOOL\Programming\Python\DNA to RNA Converter.py", line 3, in main
convert(non_coding)
File "D:\my_stuff\Google Drive\documents\SCHOOL\Programming\Python\DNA to RNA Converter.py", line 58, in convert
partA = base[0]
IndexError: string index out of range它怎么不能做base[0]的基地是'GAU'?
根据它打印的内容,“GAU”不是字符串吗?它周围没有任何报价。
提前感谢!
发布于 2012-12-22 17:19:16
它显示的不是GAU的错误,而是作为列表第二个元素的空字符串''的错误。在循环开始时添加一个测试来忽略这一点。
https://stackoverflow.com/questions/14004880
复制相似问题