Part 9c


Using Custom Modules in Python

Keeping your file system clean and managable is easy to do in Python.

Move to a subdirectory and call it lib. Create an empty file in the lib subdirectory named Delete myclass.pyc. Now you only have one file in your main directory and all your modules are in a sub directory. Rename to

Now change the import line in to add the subdirectory like so:

import lib.myclass as mc

Now from a terminal run again and you will see the following.

john@zotac:~/glade9c$ ./
calling printif with an argument
This was passed to printit
calling printit with no argument
No Argument Passed