python access


import pyodbc
import os
import pandas as pd

from configparser import ConfigParser

desktop_path = os.path.normpath(os.path.expanduser("~/Desktop"))
config = ConfigParser()
config_file = desktop_path + "\\read_ini.ini"
config.read(config_file, 'cp932')
db_path = config.get('baseconf', 'db_path')
work_path = config.get('result', 'floder')
hcsv_path = work_path + "\\本体"
gcsv_path = work_path + "\\グループ"

conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
f'DBQ={db_path}'
)

cnxn = pyodbc.connect(conn_str)
with cnxn.cursor() as crsr:
    crsr.execute(r"DELETE * FROM [申請書出力(データ)];")
    crsr.execute(r"DELETE * FROM [申請書出力(G会社)];")

cur = cnxn.cursor()
cur.execute("INSERT INTO [申請書出力(データ)] " + \
            " SELECT *" + \
            rf" FROM [text;HDR=Yes;FMT=Delimited(,);Database={hcsv_path}].csv_merge_OK_new.csv t")
cnxn.commit()

cur.execute("INSERT INTO [申請書出力(G会社)] " + \
            " SELECT *" + \
            rf" FROM [text;HDR=Yes;FMT=Delimited(,);Database={gcsv_path}].csv_merge_OK_new.csv t")
cnxn.commit()

cnxn.close()