简体   繁体   中英

conditionally import a .py or a .pyd module?

I have two modules, a "module.py" and a "module.pyd" that implements the same functions. Both modules are in the same folder. I'd would like to create a unit test that tests both the python and the extension modules against some data.

Is there any way in which I could conditionally import the .py module or the .pyd?

I could do some renaming before importing, but I would prefer a solution like being able to do import “module.py” or import “module.pyd”

if blah:
    import x
else:
    import y

Rename the native version to _module , and have the pure-Python version conditionally run

from _module import *

after the rest of its code unless a specific debugging flag is set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM