This is unfortunately what happens if you ask ChatGPT to create the code without understanding the how, when, why and what from it. There are many tutorials online that you can use to make this an easy task, if you are willing to put the effort into it -
How to Connect Python to MS Access Database using Pyodbc[
^]
Your code will look similar to this, ONLY as an example -
In your console, install the pyodbc -
pip install pyodbc
In Python, something like -
import pyodbc
db_path = r'C:\path\ToYour\database.accdb'
driver = '{Microsoft Access Driver (*.mdb, *.accdb)}'
connection_string = f'DRIVER={driver};DBQ={db_path};'
conn = pyodbc.connect(connection_string)
cursor = conn.cursor()
table_name = 'YourTableNameHere'
cursor.execute(f'SELECT * FROM {table_name}')
rows = cursor.fetchall()
for row in rows:
print(row)
cursor.close()
conn.close()