Python C++ extension with SWIG - calling a function by importing module
Question: how can I write an C++ lib and make it to an python extension with SWIG and by
importing the module `import module` it will automaticaly call an function
that initializes some global variables.

I have tried to rename the function to `__init__()`, but when I import the
module it isnt called.

what can I do?


Answer: Put the code in an init section in the SWIG interface file:

    
    
    %init %{
        my_init_function();
    %}
    

This code will be added to the generated swig wrapper and be called when
module is imported.

[SWIG 2.0](http://www.swig.org/Doc2.0/SWIGDocumentation.html) Section 5.6.2:
[Code Insertion
Blocks](http://www.swig.org/Doc2.0/SWIGDocumentation.html#SWIG_nn42)

