- 帖子
- 3232
- 精华
- 6
- 积分
- 120207
- 阅读权限
- 200
- 注册时间
- 2013-7-21
- 最后登录
- 2024-12-21
|
pyodbc- import csv, pyodbc
- # set up some constants
- MDB = 'c:/path/to/my.mdb'; DRV = '{Microsoft Access Driver (*.mdb)}'; PWD = 'pw'
- # connect to db
- con = pyodbc.connect('DRIVER={};DBQ={};PWD={}'.format(DRV,MDB,PWD))
- cur = con.cursor()
- # run a query and get the results
- SQL = 'SELECT * FROM mytable;' # your query goes here
- rows = cur.execute(SQL).fetchall()
- cur.close()
- con.close()
- # you could change the mode from 'w' to 'a' (append) for any subsequent queries
- with open('mytable.csv', 'wb') as fou:
- csv_writer = csv.writer(fou) # default field-delimiter is ","
- csv_writer.writerows(rows)
复制代码 没用过,网上搜的 |
|