The whichdb module can be used to figure out which database handler was used for a given database file, as shown in Example 10-2.
Example 10-2. Using the whichdb Module
File: whichdb-example-1.py import whichdb filename = "database" result = whichdb.whichdb(filename) if result: print "file created by", result handler = _ _import_ _(result) db = handler.open(filename, "r") print db.keys() else: # cannot identify data base if result is None: print "cannot read database file", filename else: print "cannot identify database file", filename db = None
Example 10-2 uses the _ _import_ _ function to import a module with the given name.
Core Modules
More Standard Modules
Threads and Processes
Data Representation
File Formats
Mail and News Message Processing
Network Protocols
Internationalization
Multimedia Modules
Data Storage
Tools and Utilities
Platform-Specific Modules
Implementation Support Modules
Other Modules