I have write down a code to fetch scientific literature, given code bellow fetch "xml" file and extract desired data or lines from the large file.
from this file i want two lines to be printed that contains tag "AbstractText" or "Title", when I use either "AbstractText" or "Title" with "if" it prints desirable out put but when i used both the tags with "or" statement code starts to print all the lines.
Code which is not running correctly:
def fetch_abstract(pmid):
handle = efetch(db='pubmed', id=pmid, retmode='xml')
lines = handle.readlines()
for line in lines:
if "<AbstractText>" or "<Title>" in line:
print line,
fetch_abstract("19555725")
Code is running correctly with "AbstractText" tag :
def fetch_abstract(pmid):
handle = efetch(db='pubmed', id=pmid, retmode='xml')
lines = handle.readlines()
for line in lines:
if "<AbstractText>" in line:
print line,
fetch_abstract("19555725")
Code is running correctly with "Title" tag:
def fetch_abstract(pmid):
handle = efetch(db='pubmed', id=pmid, retmode='xml')
lines = handle.readlines()
for line in lines:
if "<Title>" in line:
print line,
fetch_abstract("19555725")
how can i solve this problem ?