I have a module in my program, which is imported and used in pretty much every other module in my program.
The usage is both in global (file) scope and in local (function) scope.
I want to be able to configure my entire system to work also with a different module, in other words - I want to be able to replace that module "under the hood" in a clean manner.
The two modules share the same API of course.
I have established the following solution for this:
- Implement the functionality of both modules in the same module
- Add a
toggle
function within that module, which determines which functionality is in use - Call that function at the very beginning of my program, i.e., at the top of the Python file which I execute from a command-line:
import baseModule
baseModule.toggle(True)
But this feels extremely "unorthodox"; is there a more conventional/pythonic way of doing this?