how to use python whichdb module

Namaste Friends,

Friends, many time we face unreal small but complex problem related to identifying file database type and version.

and That's why In Python, Their Is a built-in module called whichdb module.

let's start with some basic queries

Q 1. What is python whichdb module?

Ans. Python Whichdb module help us in identifying file database version and database structure type used for recording data into a file. In simple words, this module help us to determine which DBM library should be used to open database file.

Q 2. How whichdb works?

Ans. In this function, we only need to pass file path as a argument at the time of calling this function. Then this function start its work for finding database structure type and returns the string name of the module to use to open the database file or return Empty string if whichdb not able to identifying database type and structure. If there is any type of problem in opening database file, then its return None.

Python Whichdb Tutorial With Example.

Input : [1]  

# ==================================================
# ==================================================
# author   : suraj singh bisht
# contact  : SSB
# Here, For This Tutorial
# I am using
# Operating System : Ubuntu 16.04
# Python Version   : python 2.7.12
# Editor           : ipython notebook

Output : [1]  


Input : [2]  

# Import Module
import whichdb
import os

Output : [2]  


Input : [3]  

# To Show Practical Usages Of Whichdb module
# I already copied some database in current directory.
# Let Me Show You Current Directory Files List
print os.listdir(".")

Output : [3]  

['.ipynb_checkpoints', 'example_database_shelve.db', 'Whichdb_Part_1.ipynb', 'example_database_anydbm.db', 'sqlite_database.db']

Input : [4]  

# As you can see, in above example output.
# I already copied 2-3 types of database in 
# my current directory.
print ['example_database_shelve.db',  'example_database_anydbm.db', 'sqlite_database.db']

Output : [4]  

['example_database_shelve.db', 'example_database_anydbm.db', 'sqlite_database.db']

Input : [5]  

# Now, let's check these database types with whichdb module
for i in ['example_database_shelve.db',  'example_database_anydbm.db', 'sqlite_database.db']:
    print " Database Path : {} | Database Type : {}".format(i,whichdb.whichdb(i))

Output : [5]  

 Database Path : example_database_shelve.db | Database Type : dbhash
 Database Path : example_database_anydbm.db | Database Type : dbhash
 Database Path : sqlite_database.db | Database Type : 

Input : [6]  

# Hence, as you can see in above example output
# This Module is good in identitying only types of database.
# Sp, This Tutorial finish here! 

Output : [6]  


Hence This Tutorial Ends Here.

Some Useful links For You:

Anydbm Module
Sqlorm (sqlite3 Object Relational Mapper)
Shelve Tutorial

if you like my tutorial,
Then Follow Us, Join Us and Comment Below

Written By

Share this

Related Posts

Next Post »