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 ...
Get Modular Programming with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.