[C++-sig] problem importing my own module

Benjamin Collar collar at gamic.com
Mon Oct 13 16:27:33 CEST 2003


Greetings again

I forgot one example. This causes it to core as well:

    handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
    handle<> main_namespace(borrowed( PyModule_GetDict(main_module.get()) ));
    handle<> l_module(PyImport_ImportModule("PyMuranLog"));
    handle<> x( PyRun_String(
    "hello = file('hello.txt', 'w')\n"
                           "hello.write('Hello world!')\n"
                           "hello.close()", Py_file_input,
                           main_namespace.get(), main_namespace.get()) );

Again, thanks for your help

Ben

On Monday 13 October 2003 16:20, Benjamin Collar wrote:
> Greetings
>
> Here's the other problem I've been fighting with today and haven't found an
> answer for yet.  Perhaps I've totally misunderstood what has to be done in
> my code. I'd appreciate it if someone could help me accomplish the
> following.
>
> 1. Write a module that exposes a little bit of my library code
> 2. Using the embedded interpreter, evaluate a python script which imports
> the code written in 1.
>
> So far:
> 1. I've gotten a script to import the module I made and print some
> results--just calling the script from the command line.
> 2. However, whenever I attempt "import MyModule" with code like what's
> below, I get an core dump:
>
>     handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
>     handle<> main_namespace(borrowed( PyModule_GetDict(main_module.get())
> )); handle<> x( PyRun_String(
>       "import PyMuranLog"
>       , Py_file_input, main_namespace.get(), main_namespace.get()) );
>
> Thanks for any help or explanation. I guess I'd really like know what kind
> of linking or C code is necessary to allow importing my module in the
> script.
>
> The module (built with bjam under the boost/libs/python directory) is
> available within the PYTHONPATH. I also copied the .so to
> /usr/lib/python2.2/site-packages but it still core dumps.
>
> I don't mind having a PyImport_AddModule call in my code, but I haven't
> gotten any of those sort of calls working yet either.
>
> Sincerely
> Ben

-- 
----------------------------------------

(o__      Benjamin Collar
//\       GAMIC mbH  ++49 (0)241 889 110
V_/_      Developer/System Administrator 

To know recursion, you must first know recursion





More information about the Cplusplus-sig mailing list