Python Tools – 4 Major Utilities of Python

Free Python course with 25 real-time projects Start Now!!

In this Python Tools tutorial, we will focus on – Python Dis modules, Python PDB module, Python Profile module, and Python Tabnanny module with examples.

So, let’s start with Python Tools.

Python Tools

Which Python Tools are Commonly Used?

Here, we will discuss 4 types of Python Utilities.

1. Python Dis Module

To convert bytecode into a more human-readable format, Python has the ‘dis’ module.

You can say that it compiles a script, disassembles the bytecode, and prints the output to the STDOUT.

You can use it as a module or through the command line.

As an argument, we can pass a function, a method, a class, or a code object to the dis() function.

For Example

>>> def add():
>>> add()

Now, we import the Python dis module and call the dis() function on it.

>>> dis.dis(add)

2   0 LOAD_CONST   1 (3)

2 STORE_FAST 0 (a)

3    4 LOAD_CONST   2 (4)

6 STORE_FAST  1 (b)

4    8 LOAD_FAST    0 (a)

10 LOAD_FAST  1 (b)


14 STORE_FAST       2 (c)

5    16 LOAD_GLOBAL 0 (print)

18 LOAD_FAST 0 (a)


22 LOAD_CONST 3 (‘+’)

24 LOAD_FAST 1 (b)


28 LOAD_CONST 4 (‘=’)

30 LOAD_FAST 2 (c)





40 LOAD_CONST 0 (None)


2. Python Tabnanny Module

Python tabnanny checks code for ambiguous indentation.

It tells us about any weird combinations of tabs and spaces in the code. In Python, whitespace shouldn’t be ambiguous.

Like dis, we can run tabnanny from the command line or using the function check().

>>> import os
>>> import tabnanny
>>> os.chdir('C:\\Users\\lifei\\Desktop')
>>> tabnanny.check('')

Python Tabnanny module has the following methods:

Python Tabnanny Module


a. tabnanny.check(file_or_dir)

This checks the file or directory we pass to it for examining whitespace-related issues. Then, it prints the diagnostic messages to the standard output.

b. tabnanny.verbose

This is a flag that depicts whether Python will print verbose messages.

c. tabnanny.filename_only

This is a flag that depicts whether Python should print only the filenames for those files that contain issues involving whitespace. It also has the following function:


The tokenize module generates some tokens. check() uses process_tokens() to process these tokens.

Finally, this module may raise the following exception:

exception tabnanny.NannyNag

When process_tokens() detects an ambiguous indent, it raises this exception. check() captures and handles this.

3. Python Profile Module

We may sometimes like to know which parts of our code take the longest. So in a way, through profiling, we try to find bottlenecks in our code.

Other profilers in Python are cProfile and hotshot.

Let’s try this module with the cProfile module.

>>> import hashlib
>>> import cProfile

4 function calls in 0.000 seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)

1 0.000 0.000 0.000 0.000 <string>:1(<module>)

1 0.000 0.000 0.000 0.000 {built-in method _hashlib.openssl_md5}

1 0.000 0.000 0.000 0.000 {built-in method builtins.exec}

1 0.000 0.000 0.000 0.000 {method ‘disable’ of ‘_lsprof.Profiler’ objects}

We profile the creation of an MD5 hash here. The first output we get tells us that four function calls were made. These are ordered by standard name.

Here’s what all the other columns mean:

  • ncalls- The number of calls made.
  • tottime- Total time spent in a function.
  • percall- The quotient of tottime divided by ncalls.
  • cumtime- Cumulative time spent in this function and all subfunctions.
  • percall- The quotient of cumtime divided by primitive calls.
  • filename: lineno(function)- Data of each function.

4. Python PDB Module

Pdb is the standard Python debugger. It helps us debug our code line by line.

>>> import pdb
>>> n=4
>>> def raised(a):
      return a**a
>>> print(eight)
>>> two=raised(2)
>>> print(two)

In the command prompt:


> c:\users\lifei\desktop\<module>()

-> seven=raised(7)


Now, we can use the commands of the pdb module to debug our code.

Important Interview Questions on Python Tools

  1. What are the various Python Tools and why they are used?
  2. Explain Python PDB Module.
  3. What are Profilers in Python and name some Python Profilers.
  4. Name some methods in Tabnanny Module.
  5. What is the use of Dis Module in Python?


These are few basic tools and utilities of Python: Dis modules, PDB module, the Profile module, and Tabnanny module with an example.

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google | Facebook

3 Responses

  1. Rajkamal Mishra says:

    In this blog, the spelling of tabnanny is written as tbnanny in diagrams. Is there any specific reason for that or just a typo error.

  2. Abdul says:

    Hello there, Data Flair.

    My opinion on python tools should be cover at the end of intermediate level because at the beginning it will cause problems for freshman learning python but is good context to follow for being a good python engineering

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.