samedi 21 mars 2020

Testing with Optional Import in Python

I have a library that can use two modules; one is fast but available only on Linux and macOS, the other is slower but it's multi-platform. My solution was to make the library compatible with both and have something like the following:

try:
    import fastmodule
except ImportError:
    import slowmodule

Now I want to compare the timing of the library when using either module. Is there any way of masking the fastmodule without changing the source code (i.e. within a Jupyter Notebook), in an environment where both modules are installed, so that the slowmodule is used?

Aucun commentaire:

Enregistrer un commentaire