What makes a module reusable?
In order for a module or package to be reusable, it has to meet the following requirements:
It must function as a standalone unit
If your package is intended to be included as part of the source code for another system, you must use relative imports to load the other modules within your package
Any external dependencies must be clearly noted
If a module or package does not meet these three requirements, it would be very hard, if not impossible, to reuse it in other programs. Let's now take a closer look at each of these requirements in turn.
Functioning as a standalone unit
Imagine that you decide to share a module named encryption
, which performs text encryption using public/private key pairs. Another programmer then copies this module into their program. When they try to use it, however, their program crashes with the following error message:
ImportError: No module named 'hash_utils'
The encryption
module may have been shared, but it was dependent on another module...