gpt4 book ai didi

Python Dict : TypeError: list indices must be integers, 不是 str

转载 作者:太空宇宙 更新时间:2023-11-04 03:28:08 25 4
gpt4 key购买 nike

这段代码来自一个脚本,该脚本获取包含 UniProt 代码存储在字典中的 PDB(蛋白质数据库)代码:DDomainSeq。

这是 DDomainSeq Dic 的样本:

{'3.30.67.10': ['G3GAK5', 'I3QCE1', 'G3EN69', 'K4LBV0', 'Q2XWS4', 'D6MQ73', 'F1D844', 'Q8JTJ9', 'H9U1G9', 'B1PNF1', 'B3F7E1', 'Q9J0E6', 'K4LBK6', 'Q2XRW4', 'D0EPQ6', 'D3U0G6', 'Q8QMF3', 'J9PQ44', 'B9W116', 'Q2XRW9', 'I3QCH7', 'K7R4A7', 'I7B1H2', 'B1PNH0', 'I3QCD9', 'Q82861', 'I3QC33', 'Q2XRJ4', 'E3UMQ4', 'B9V561', 'Q8BE43', 'Q80QJ9', 'E0YAP9'], '2.60.98.10': ['C9WJC0', 'B3TN06', 'Q9IZI7', 'Q9WDA0', 'A9LIM6', 'C5MSX3', 'Q6Q6Q1', 'Q3LFV0', 'E5RCU8', 'I6XG39', 'G5EJD7', 'D3X8F0', 'Q2XRV6', 'D0QXC4', 'I7EMG2', 'A4UIW9', 'Q89283', 'H9M657', 'F2YLD8', 'Q2YGV6', 'D6MQ23', 'G9F8Y6', 'G8G189', 'H8Y6K8', 'E3UMP9', 'Q91AG4', 'I3QCA4', 'A4K4T3', 'H6VBW8', 'D8FSI8', 'D0TYZ3', 'I3QCM1', 'H6VBX9', 'C0JZP9', 'C6ZE88', 'A1BY35', 'I7A3V7', 'Q2XRZ1', 'A5YBK7', 'Q66463', 'C3V004', 'Q6YG48', 'Q2ESB0', 'H1ZYK5', 'Q00P61', 'E2IZW1', 'D0VF46', 'K4IYH8', 'Q9IJX6', 'Q87046', 'Q9WB77', 'C7T0M1', 'I3QC70', 'E2IGI0', 'Q32ZL8', 'C8CKT7', 'D6MM36', 'Q3LFN6', 'F5AXV2', 'I6PGU1', 'B9W157', 'K7PP62', 'Q3Y6G7', 'Q6YFX6', 'C9WPK5', 'G9IBD9', 'G9DR11', 'C1KKF7', 'I6WJM3', 'K7PPW7', 'Q3S2G1', 'Q6WP68', 'H2D5H7', 'H2D5I3', 'K7QRY5', 'Q9WLZ8', 'F5AXW1', 'Q8JTJ2', 'E3UMM2', 'B9VHE4', 'B6E979', 'Q2YH31', 'A7TUC9', 'D3X8C3', 'H2D5I2', 'B6EBW6', 'F2WS10', 'Q2YH68', 'C1KKE8', 'B0LCR1''A3GPY8']}

每个键中的每个元素都用于搜索在 PDBSum 数据库中找到的 PDB 文件。

PDBSumWWW = urllib.urlopen("https://www.ebi.ac.uk/thornton-srv/databases/pdbsum/data/seqdata.dat")
PDBSum = PDBSumWWW.read().splitlines()
PDBSumWWW.close()

这是我为此使用的代码:

for domain in dDomainSeq.keys():
print domain
PDB = []
for uni in dDomainSeq[domain]:
for i in range(len(PDBSum)):
if "SWS_ID" in PDBSum[i]:
str = PDBSum[i]
splited = str.split()
if uni in splited[2]:
PDB.append(splited[0])
print PDB
print len(PDB)
PDBSum[domain]=PDB

但是在加载所有 PDB-UniProt 代码匹配第一个键“3.30.67.10”后,它显示以下错误:

Traceback (most recent call last):
File "/Users/ThePoet/Dropbox/MBID/MSc Summer Project/Program/SeqPDBSum.py", line 57, in <module>
main()
File "/Users/ThePoet/Dropbox/MBID/MSc Summer Project/Program/SeqPDBSum.py", line 45, in main
PDBSum[domain]=PDB
TypeError: list indices must be integers, not str

最佳答案

尝试获取字典

varofdictionary = {}

PDBSum 是一个列表,因此您应该创建一个空字典并附加到它。

关于Python Dict : TypeError: list indices must be integers, 不是 str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32203316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com