Easiest way to access C module in Python
Lele Gaifax
lele at metapensiero.it
Tue Nov 7 14:07:56 EST 2017
Gisle Vanem <gisle.vanem at gmail.com> writes:
> python.exe -c "import life; print(life.life())"
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> AttributeError: 'module' object has no attribute 'life'
>
> Can you give a hint?
I tried with Python 2, and the same recipe works for me, on GNU/Linux:
$ python -c "import life; print life.life()"
42
I'm sorry, but I have no opportunity to try on a M$Windows system.
Anyway, is your interpreter able to load the extension module produced by the
"setup.py build_ext" step?
On my PC, I get the following, using the "-v" option to verbosely see the
imported modules:
$ $ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
...
>>> import life
dlopen("./life.so", 2);
import life # dynamically loaded from life.so
>>> dir(life)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__', 'life']
Can you try to import the "life" module and print its "dir()" to see the
symbols it exposes?
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it | -- Fortunato Depero, 1929.
More information about the Python-list
mailing list