Part 9c
Libraries
Using Custom Modules in Python
Keeping your file system clean and managable is easy to do in Python.
Move myclass.py to a subdirectory and call it lib. Create an empty file in the lib subdirectory named __init__.py. Delete myclass.pyc. Now you only have one file in your main directory and all your modules are in a sub directory. Rename glade9b.py to glade9c.py.
Now change the import line in glade9c.py to add the subdirectory like so:
import lib.myclass as mc
Now from a terminal run glade9c.py again and you will see the following.
john@zotac:~/glade9c$ ./glade9c.py
calling printif with an argument
This was passed to printit
calling printit with no argument
No Argument Passed