Can I create a module that uses functions that will be supplied by importers of the module?
I want to write generic code without specifying the implementation of a few key functions. I want the user to specify these. I could include these as inputs to all functions but this seems ugly.
If I were writing an object I would create an abstract class. Is there an equivalent for modules?
Edit: I’m asking specifically about how to do this with functions in modules, not methods in classes.
It is possible to monkey patch a module and add new functions to a module at runtime.
However this is frowned upon in the Python community. It is inherently unstable as this will affect all users of this module. For instance, if you use another module which also uses the module that you have monkey patched, your other module may show erratic behavior that is hard to debug.
For what you want to do you’d better create an abstract class 🙂