这是我正在遍历的 XML 树的示例:
<entry dataset="Swiss-Prot" created="1993-07-01+01:00" modified="2013-04-03+01:00" version="144">
<accession>P31750</accession>
<accession>Q62274</accession>
<accession>Q6GSA6</accession>
<name>AKT1_MOUSE</name>
<protein>
<recommendedName>
<fullName>RAC-alpha serine/threonine-protein kinase</fullName>
<ecNumber>2.7.11.1</ecNumber>
</recommendedName>
<alternativeName>
<fullName>AKT1 kinase</fullName>
</alternativeName><alternativeName>
<fullName>Protein kinase B</fullName>
<alternativeName>
<fullName>Some other value</fullName>
</alternativeName><alternativeName>
..........
我正在努力达到alternativeName
. 我没有任何问题recommended name
,所以我尝试使用相同的方法alternativeName
。但是,Python
解释器输出以下错误消息:
for child in protein.find("{http://uniprot.org/uniprot}alternativeName"):
TypeError: 'NoneType' object is not iterable
这是Python
我用来获取这些元素的代码。同样,该代码适用于recommendedName
但不适用于alternativeName
. 谢谢你的帮助!
alt_shortnames = []
alt_fullnames = []
protein = e.find("{http://uniprot.org/uniprot}protein")
for child in protein.find("{http://uniprot.org/uniprot}alternativeName"):
if child.tag == "{http://uniprot.org/uniprot}fullName":
alt_fullnames.append(child.text)
if child.tag == "{http://uniprot.org/uniprot}shortName":
alt_shortnames.append(child.text)
temp_dict["alternativeFullNames"] = alt_fullnames
temp_dict["alternativeShortNames"] = alt_shortnames