将Bio.Entrez类转换为字符串

时间:2016-11-21 00:56:52

标签: python string biopython

我目前正在使用BioPython从PMID查询PubMed记录。然后,我将所需信息存储在名为abstract的变量中,数据类型为:

class 'Bio.Entrez.Parser.StructureElement'>

例如,如果我打印它,我会收到:

{u'AbstractText': ['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']}

我希望将方括号之间的文字写成字符串。我怎样才能快速有效地做到这一点?

2 个答案:

答案 0 :(得分:0)

我不知道您是如何从PubMed获取数据的,但如果您需要查询PubMed并获得摘要,则可以使用以下代码段。

*

<强>输出

  

'高胆固醇血症和高血压常与

有关      

...

     

高胆固醇血症高血压患者的结构性损害。'

答案 1 :(得分:0)

您应该将其识别为Python词典:

{u'AbstractText': ['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']}

此处'AbstractTest'是字典键,['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']是其关联值。

注意['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']是一个包含一个字符串的Python列表(显示用点截断)。

因此my_dict['AbstractTest'][0]之类的内容会为您提供此列表中的第一个条目。