我想解析一个文件来搜索一个单词然后打印下一行我写了如下的python脚本
infile = open("s.sdf","r")
output = open("sample.txt","w")
d = None
HD = None
HA = None
M = None
for line in infile:
if line.startswith("> <PUBCHEM_COMPOUND_CID>"):
d = infile.next().strip()
print d
elif line.startswith("> <PUBCHEM_CACTVS_HBOND_DONOR>"):
HD = infile.next().strip()
print HD
elif line.startswith("> <PUBCHEM_CACTVS_HBOND_ACCEPTOR>"):
HA = infile.next().strip()
print HA
elif line.startswith("> <PUBCHEM_MOLECULAR_WEIGHT>"):
M = infile.next().strip()
print M
print "%s \t %s \t %s \t %s" %(d,HD,HA,M)
output.write("%s \t %s \%s \t %s" %(d,HD,HA,M))
但不幸的是我收到如下错误
None None None None
None None None None
None None None None
None None None None
.......
有谁能告诉我如何解决这个问题..
先谢谢
<磷>氮