Skip to main content

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

Related Post

Top Visited

Big List Of Google Dorks For Sqli Injection

List of Keyboard Shortcuts Keys for GNOME Desktop (Kali linux / Linux / Ubuntu/*nix )

how to install burp suite in Linux/Ubuntu 16.04

Create Simple Packet Sniffer Using Python

How to create Phishing Page Using Kali Linux | Webpage Page Cloning Using Kali Linux Social Engineering Toolkit

Best 1000 User-agents List For Web Scraping

How To Install GDB Peda?

2 Easiest Way To Enable Monitor Mode in Kali Linux | Airmon-ng | Iwconfig

Latest Google Dorks List

How To Create Snake Game Using Python And Tkinter - Simple python games