[IPython-dev] Different behaviour: python vs. ipython when using a C module

Fernando Perez fperez.net at gmail.com
Mon Oct 16 03:39:08 EDT 2006

On 10/16/06, Stefan Reichör <stefan at xsteve.at> wrote:
> Hi!
> I use python in C/C++ Applications for scripting.
> I have implemented a C/C++ library that is used in that application.
> To test that library, I use python (preferred ipython).
> That works very well.
> Now I have added an embedded python interpreter to the C/C++ library.
> That interpreter makes the library very easy customizable.
> But with this setup I discovered a different behaviour when I compare
> python with ipython. The python version works like I expect. When I
> use ipython, it does not work.
> Now I'd like to find out, if this is a bug in ipython, that can be
> fixed, or if I do something wrong.

Well, I'm not really sure: you are doing something a bit odd, and I
honestly don't know if it's correct or if you're getting away with
murder by accident.  Your enclosing init function does this:

void inittestmodule() {
  Py_InitModule("testmodule", testmoduleAccessMethods);


  printf("Before import embedmodule\n");
  PyRun_SimpleString("import embedmodule");
  printf("After import embedmodule\n");


It initializes a second internal module, 'embedmodule', inside itself.
 I don't have the foggiest idea whether this trick of creating a
module within another is kosher at the C-API  level (I know it can be
done in pure python using the 'new' module).

I realize it works in pure python, so I'd be inclined to say it's an
ipython bug: ipython should always let you do things that are valid
python.  But I honestly don't know what the solution is here, nor even
if it's not a fluke that it works for the pure python case.

I'll be glad to fix this one if we could understand better the
problem, so if anyone knows what's going on, by all means pitch in.



More information about the IPython-dev mailing list