Monday, January 2, 2017

Python Modules - Simple Example

I have written a lot of Python code in last year or so, but I realized that I have not been doing the modules and the import of modules properly. I have been concentrating mostly on the logic of my applications and I have ignored the distribution part of the modules and these applications. Yes, my applications have been mostly POCs for my team and some tools, but these still deserve to be implemented to enterprise standards.

There is a lot of material on internet about Python modules, but it takes time to conclude what the simplest way is. I spend last few days doing some research and trying out things until I arrived at something simple and what I believe could be used at the enterprise level.

I am in the process of learning this and I decided to document it for others with very simple examples that you can download and try yourself.

Click HERE to download the code from my Google Drive.

Below are the screenshots of the code structure. You will see that there are two modules that are bundled under one module_util:

  • util_general
  • util_math

To make the example more realistic, the util_math module using code from util_general module. 

The code in main.py shows you you can properly import the modules and use the functions from these modules. 












NOTE:

My next post will be about making some additions in this code to make this code distributed in the form of Python eggs.

Then the post after that will about using this Python egg in a different application as a black box.



Almir M.

No comments:

Post a Comment