How to create mdb database file in Python?

I would like to create a mdb database file on Windows with Python and cannot figure it out using Python Docs. Everything I read is connected and connected with the cursor.

Any thoughts? Thanks...

+4
source share
1 answer

My experience with the comtypes module was pretty good. You will probably want to have access to DAO / ADO / VBA to access the methods that are used, however, since the comtypes module dynamically generates COM library wrappers, so there is no built-in documentation.

Here is a brief example of how this works. (Go and check for yourself.)

 from comtypes.client import CreateObject access = CreateObject('Access.Application') from comtypes.gen import Access DBEngine = access.DBEngine db = DBEngine.CreateDatabase('test.mdb', Access.DB_LANG_GENERAL) # For me, test.mdb was created in my My Documents folder when I ran the script db.BeginTrans() db.Execute("CREATE TABLE test (ID Text, numapples Integer)") db.Execute("INSERT INTO test VALUES ('ABC', 3)") db.CommitTrans() db.Close() 

(Moved the second import statement after the CreateObject line for cases where the Python wrapper module for the sample library did not previously exist.)

+10
source

Source: https://habr.com/ru/post/1313532/


All Articles