Easiest way to access C module in Python

bartc bc at freeuk.com
Tue Nov 7 16:00:15 EST 2017


On 07/11/2017 20:08, Gisle Vanem wrote:
> Lele Gaifax wrote:
> 
>> 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?
> 
>  From inside python 2.7:
>    Python 2.7.13rc1 (v2.7.13rc1:4d6fd49eeb14, Dec  3 2016, 21:49:42) 
> [MSC v.1500 32 bit (Intel)] on win32
>    Type "help", "copyright", "credits" or "license" for more information.
>    >>> import life
>    >>> dir(life)
>    ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 
> '__test__']
>    >>>
> 
> works fine.

Not really, as it's missing the attribute 'life' which is needed for the 
second part of 'life.life':

  But as I wrote, doing a:
>    python -vc "import life; print(life.life())"

-- 
bartc



More information about the Python-list mailing list