我的代码在XML文件(函数“findTerminal”)中搜索特定的属性名称,并将其传递给另一个函数(称为DBAccess)以查找访问数据库中的attribut。 属性名称没有在数据库中连接,我必须这样做才能进行比较。 当我执行代码时,什么都没发生?
import csv
import pyodbc
from xml.dom import minidom
# *************************************
def DBAccess (Term):
MDB = 'c:/test/mydb.mdb'
DRV = '{Microsoft Access Driver (*.mdb)}'
PWD = ''
conn = pyodbc.connect('DRIVER=%s;DBQ=%s;PWD=%s' % (DRV,MDB,PWD))
curs = conn.cursor()
print 'connexion opened'
SQL = 'SELECT * FROM gdo_arc;' # insert your query here
curs.execute(SQL)
curs.execute("select nat_arc from gdo_segment")
rows = curs.fetchall()
for row in rows:
T = 'T' + row.tronson + '_' + row.noued1 + '-' + row.noued2
if T == Term :
print (' Terminal found')
curs.close()
conn.close()
#*************************************
def findTerminal():
xmldoc = minidom.parse('c:\\test\mydoc.xml')
#printing the number of blocs in my xml file
itemlist = xmldoc.getElementsByTagName('ACLineSegment')
for item in itemlist:
found = False
for child in item.childNodes:
if child.nodeName == 'Terminal':
found = True
if not found:
Term = item.getAttribute('Name')
DBAccess (Term)
#***********************************
findTerminal()