Python's module system is something we have been using throughout the book. It is what lies behind the import statements.
All that we need to do in order to create a module is make a Python file. It really is that simple. Let's take a small example. Create a new folder to hold our example and add a short simple file:
# mymod.py
myvariable = 15
def do_a_thing():
print('mymod is doing something')
def do_another_thing():
print('mymod is doing something else, and myvariable is', myvariable)
This may look the same as any normal Python file, but we can treat this as a reusable module if we want to. To demonstrate, open up a terminal window, change into the directory you have just created with this file in, and then run the Python REPL:
>>> import mymod
>>> mymod.do_a
mymod.do_a_thing( mymod.do_another_thing...