Making work easier, modules style

Code, there is a lot to it, isn’t there? Welcome then to the wonderful magic that is modules, especially in Python.

So, what exactly are modules. They are Python files, well not necessarily Python, whichever language, that contain classes and functions. That is essentially what they are, Python files with functions.

This makes programming even easier, because your code becomes reusable and your work is just calling functions from a module.

The import statement

If you were to use a module in a project, you would have to import the module like so, just after the PATH

import <module name>

Let me stop beating around the bush…

This module will add up two numbers like so…

#!usr/bin/python

blue = int(raw_input("Feel like giving me a number?"))
green = int(raw_input("How about another?"))

def addy(blue,green):
    white = blue + green
    print white
def addy(blue,green)

Then I would save it with the name addy.py. If I then come to another file, I would import it as so..

#!usr/bin/python

import addy

blue = int(raw_input("Hey there, give me a number"))
green = int(raw_input("How about another?"))

#I can then call the function here
addy(blue, green)

So, there you have it, making work easier one byte at a time

Challenge:

Try making a module of something that makes your life a whole less harder. Make it interesting, like a module that can compute how much money you spend in a week.

Ah, I sense the force getting stronger…

Written on July 20, 2016