I have a Python pyd module written in C++. I also have a Python version of the module (which is much slower). My question is, as I want the program to run on multiple OSs, can I try to import the C++ version in the program and import the slower Python version if that one fails (other OS, architecture)?
Asked
Active
Viewed 274 times
2 Answers
6
Yes, you can import some thing like this:
try:
import CppModule as Module
except ImportError:
import PurePythonModule as Module

BGE
- 135
- 5
2
Yes you can:
try:
import CppModule
except ImportError:
import PythonModule
Edit: This answer, while not incorrect, is not really useful. As @Best Games' answer shows, this only really useful if you import the module using a common name.

Björn Pollex
- 75,346
- 28
- 201
- 283