# -*- coding: utf-8 -*-
"""
Created on Wed Dec 5 16:43:28 2018
@author: chealia
"""
import xlrd
from xlutils.copy import copy
from xml.parsers.expat import ParserCreate
rb=xlrd.open_workbook(r'c:\users\chealia\201812\drug.xlsx')
wb=copy(rb)
global i
i=0
global j
j=0
global flag
flag=0
c1=wb.get_sheet(0)
class DefaultSaxHandler(object):
def start_element(self,name,attrs):
global i #全局变量在使用前还要再声明一次,切记!
global flag
global j
if i>65535:
return
if name=='drug' and flag==0:
c1.write(i,0,attrs.get('type'))
flag=0
j=i #第j行就是第i行
i=i+1
if name=='drugbank-id' and flag==0:
flag=1
if name=='name' and flag==10:
解析drugbank xml文件的代码。(先要把文件里的换行符删干净了)
最新推荐文章于 2024-06-01 17:18:53 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)