Saving dictionaries

There is no shortage of ways to save information in Python but if you naturally have the information in a dictionary or an array have a look at a NoSQL database. There are several different types to cover different use cases but a good one to start with is MongoDB. It allows you to save and retrieve arbitrarily complex dictionaries with the minimum of fuss.

One reason to suggest this is they have made learning it easy. They run a free online video based course (M101P) roughly every 2 months with any code outside of Mongo written in Python. I’ve just successfully completed it and I can recommend the course.

If you prefer a book for learning, JSbooks have The Little MongoDB Book you can read. My preference is for the online course but the book is easy to read and useful if you don’t have an Internet connection.

64bit v 32bit ODBC

Although Python is available in 64- and 32-bit versions, there are not many times when it makes a massive difference. One time it will is when you use ODBC. As we are talking about drivers here, if your app (or in our case Python build) is 32bit you will need to use a 32bit ODBC driver and if you app is 64bit you will need a 64bit driver.

Under a 64bit version of Windows, you will have two versions of the ODBC Administrator tool available. Naturally the 32bit version is used to configure the 32bit ODBC drivers and the 64bit version (the one available from the Control Panel) is for 64bit drivers. Confusingly both tools show 32bit and 64bit user DSN even through they can only configure one, see Microsoft article KB942976 for details. To get to the 32bit version run


Still you probably use the ADODB COM interface and these are not 64-/32-bit dependent right? Unfortunately not. This still relies on the the same mechanism as ODBC, so you will need the correct drivers installed.

This caught me out when I tried to open an Access 2007 database and couldn’t understand the error message. Office 2007 is still a 32bit application and hence only installs 32bit ODBC drivers. It was not until 2010 that you had the option of a 64bit version. So what should have been a simple few lines to connect just produced an error.

# Worked under
import win32com.client
dbcom = win32com.client.Dispatch('ADODB.Connection')
connstr = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\PathToDB\\dbfile.accdb;Uid=Admin;Pwd=;"
db = dbcom.Open(connstr)

It wasn’t until I dropped back to a 32bit build of Python and the same lines worked was I finally sure the problem was with the ODBC driver. Running this with a 64bit build produced the following error

Exception occurred. Provider cannot be found. It may not be properly installed

The correct fix is to install the correct drivers, although this might not be as easy as it should be. When I tried installing the 64bit Microsoft Access Database Engine 2010 Redistributable it refused to install because I the 32bit Office installed.

Another work around would be to use the COM interface to the Access application itself, although this will only work on computers where MS Access is installed.