我一直在学习通过 swig 扩展 python。在 swig 导师中,它写道:
Building a Python module
Turning C code into a Python module is also easy. Simply do the following (shown for Irix, see the SWIG Wiki Shared Libraries page for help with other operating systems):
unix % swig -python example.i
unix % gcc -c example.c example_wrap.c \
-I/usr/local/include/python2.1
unix % ld -shared example.o example_wrap.o -o _example.so
We can now use the Python module as follows :
>>> import example
>>> example.fact(5)
120
>>> example.my_mod(7,3)
1
>>> example.get_time()
'Sun Feb 11 23:01:07 1996'
>>>
这意味着可以将共享库作为python模块导入。但是我知道共享库文件是由许多机器代码和一些额外信息组成的目标文件,而常规python模块是ascii文件或字节码文件, python虚拟机如何执行机器代码,我很困惑。