在python中读写数据库表 [英] Reading and writing access database table in python
问题描述
我有一个访问数据库。里面是我创建的几个表。我想使用python读通过其中一个表,并列出列中的一切。我想将该列表与已在我的程序中创建的另一个列表进行比较,如果该列表与列表中的一个匹配,则在我访问电子表格的同一行新列中输出一个YES。类似地,如果该数字与列表中的数字不匹配,我想在数据库表上输出NO。
I have an access database. Inside are a few tables I created. I want to use python to read through one of the tables and make a list of everything in a column. I want to compare that list to another list already created in my program, and output a "YES" in the same row new column of the access spreadsheet I made, if that number matches one in the list. SSimilarly, I want to output "NO" on the database table if that number doesn't match one in the list.
我已经从另一个Excel表中取得了我的列表。我现在需要从excel表中读入文件。我不能使用模块MySQLdb,因为它不允许我在我的电脑上下载。
I have already made my list from another excel sheet. I now need to read in the files from an excel sheet. I cannot use the module "MySQLdb" for it doesn't allow me to download on my computer.
我的问题是:
如何读取和写入excel中的表格?我已经尝试了一整天,包括MySQL和其他堆栈溢出问题。他们都不符合我现在写的东西。
How can I read and write in a table in excel? I have tried everything all day including MySQL and other stack overflow questions. None of them match what I am writing right now. Thank you.
推荐答案
您可以将表格转换为csv,以便用excel打开
You can convert the table to csv so you can open it with excel
试试这个:
import csv
roomnumber = 0.00
roomname = 0.00
lueftungList = []
import time
class Lueftung:
def getData(self):
global roomnumber
global roomname
roomnumber = input("roomnumber: ")
roomname = input("roomname : ")
myFormattedList = [ '%.2f' % elem for elem in lueftungList ]
def main(self):
global roomnumber
global roomname
lueftungList.append(["", roomnumber, roomname, "", ""])
lueftungList.insert(0,[(time.strftime("%d.%m.%Y")), "roomnumber", "roomname",])
# convert to csv
with open("lueftung.csv", "w", newline="") as csvfile:
cwriter = csv.writer(csvfile, delimiter=";")
for row in lueftungList:
cwriter.writerow(row)
if __name__ == "__main__":
luft = Lueftung()
luft.main()
这篇关于在python中读写数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!