cnxn = pyodbc.connect("Driver={SQL Server};Server=localhost;Database=reportdb;uid="+v_user+";pwd="+v_pwd) cursor = cnxn.cursor() cursor.execute("select * from config where type_id='gh_zhjy'") users=[] for row in cursor: users.append(row[3]) list=[]; filename=file_path; fp=open(filename,"r",encoding='utf-8'); done=False; while not done: aline=fp.readline(); if(aline!=""): aline=aline.replace('\n','').replace(" ",""); if(aline in users): list.append('浙江国华浙能发电有限公司:'+aline.replace('\n','')); else: done=True; fp.close(); print(list);