0

我的代码在 XML 文件(函数“findTerminal”)中搜索特定属性名称,并将其传递给另一个函数(称为 DBAccess)以在 access 数据库中查找该属性。属性名称未在数据库中连接,我必须这样做才能进行比较。但是当我执行代码时什么也没发生?

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()
4

0 回答 0