import hooks

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 17 01:17:40 CEST 2008


En Wed, 16 Apr 2008 09:04:36 -0300, Patrick Stinson  
<patrickkidd.lists at gmail.com> escribió:

> I am defining a simple finder/loader object and adding it to  
> sys.meta_path
> like this:
>
> PyRun_SimpleString("import sys; import ousiainternal; sys.meta_path =
> [ousiainternal.OusiaImporter]");

You should append to the existing meta_path, not replace it, erasing any  
previous content.
And it must be an *instance* of your importer, not the type itself.
Note that you're polluting the __main__ module namespace by using  
PyRun_SimpleString; I'd use API calls like PySys_GetObject("meta_path")  
and PyList_Append (PEP 302 guarantees it is a list).

> "sys.meta_path.append(Importer)\n";

Here you append to sys.meta_path, but fail to create the instance first.

> PyRun_SimpleString(importer_source);

You should check the return value; I bet you got a -1 (failure).

-- 
Gabriel Genellina




More information about the Python-list mailing list