__import__ woes

Rich Davis rdavis at lulupress.com
Thu Mar 27 20:14:05 EST 2003


Ok, I'm trying a "Hello World" Python/C API test.  When I try the 
following, mod is null. 


        PyObject *modname, *mod, *mdict, *func, *stringarg, *args, *rslt;
        Py_Initialize();
        modname = PyString_FromString("test");
        mod = PyImport_Import(modname);

When I try to "__import__" from the command-line like

 >>> __import__("test")
<module 'test' from 'test.pyc'>
 >>> test.doIt("test string")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'test' is not defined
 >>>

it doesn't seem to work. However, "import" does.

 >>> import test
 >>> test.doIt("test string")
test string
 >>>

Can anyone point me in the right direction to a)get __import__ to work, 
so I can b) get PyImport_Import() to work.

Thanks,

Rich






More information about the Python-list mailing list