Just a very basic example how to create a Python Module that consists of a Single Class and 2 basic functions.
Our main app will can our module to print out a word, that we pass to our first function.
The Directory Setup:
Below is a tree view of my current working directory:
1 2 3 4 5 6 7
In order to make a python file a module, we need to have a blank
__init__.py file in our directory. So any files under our providers directory will be seen as modules from our
Our Test Module:
1 2 3 4 5 6 7 8
providers/test.py file will be blank.
main.py, we will import our test module, instantiate our class, and call our function within the class that we instantiated:
1 2 3 4 5 6
response = test_instance.simple_test(), you could also do
Testing it out:
It’s very basic but will post some more topics around this in the future.
Also note, this blog is for quick posts that I come accross during my daily doings, for more details tutorials have a look at my main blog: sysadmins.co.za