Based on post of Python Core Developer Andrey Svetlov.
I can suggest you to add platform/hardware specific Python modules in separate directories and append this modules to sys.path
in runtime.
For example: We have a package
- package
- __init__.py
- a.py
- x86_64
- b.py
- i386
- b.py
__init__.py
will contain something like this:
import sys
import platform
from os.path import join, dirname
__path__.append(join(dirname(__file__), platform.machine()))
With this approach common code is located in package while platform specific distributed in subdirectories.
Take attention that x86_64
and i368
do not have __init__.py
module.
Import required module b
from package import b