Understanding the Code Reuse and Modularity in Python 3:

Object oriented programming (OOP) in Python for Data Science:

It is a programming ideal that is based on the concept of the “objects” which will contain data in the form of fields known as attributes and codes in the form of procedures also known as methods.

Objects will have characteristics and features which are known as attributes. These can do various things through their methods. One of the biggest features of OOP is how nicely objects can interact and even mold in the future. This makes it friendly to developers, scale, change over time, and much more.


Modularity is the concept of making multiple modules first and linking and combining for the formation of a complete system. It will enable us to reuse and minimize duplication.

Flow of the article:

Now we will learn OOP- modularity. We will also look at turning parts of the code into a library for using it for future reference.

We will make a small environment and some objects in it. Also, we will see to it that the environment is static and the objects are modular. Here we will make use of PyGame as it will enable us to visualize what we are doing and building so, that we can see our objects in action. We will build blob world. Different blobs will have different properties, and the blobs will need to function within their blob world environment. Now, we will illustrate modularity in this example.

We will divide the process into 2 stages:

  1. Creation of environment and the blobs.
  2. Then we will understand the modularity.
Blob world code:

Understanding the Code Reuse and Modularity in Python for Data ScienceUnderstanding the Code Reuse and Modularity in Python for Data Science

Part 1: We have created a simple environment and some objects in it for visualizing our creation.

Part 2: Modularity is an essential part of OOP. We will now use modularity in the environment which we have created.

Now we will have two files. We will copy the Blob class and random and make a new file blob.py.

We will get an error in the blob.py file in connection with our Blob class, and we have some undefined variables here. Now, we will add values to the __int__ method, and we will modify the parts where we used the constants.

When we call the Blob class within our original file, the program will expect some values for the arguments, and so, we will add those in the main function.

Now we will be able to import the blob class, so it has become modular. We don’t need to provide a value for the size so; we can use a reasonable starting default.

In case the programmer wishes to change the size, it is possible. We can also modify the speed of the blob.

Now the class is quite open. We will now open the in-bounds method, and we will delete the code for keeping them in-bounds.

Understanding the Code Reuse and Modularity in Python for Data Science

So, to learn more about it in python for data science, you can check this and this as well.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.