A question?

vin fractal97 at hotmail.com
Sun Sep 9 01:02:36 CEST 2001


PyImport_GetModuleDict()  which is the same as sys.modules and which 
returns a dictionary already contains 'exmpl' 
To see that just insert 

  PyRun_SimpleString("import sys\n");
  PyRun_SimpleString("print sys.modules\n");

after 

  module=PyImport_ImportModule("exmpl");

Therefore inserting 'exmpl' module doesn't help.

Ignacio Vazquez-Abrams wrote:

> On Sat, 8 Sep 2001, Ignacio Vazquez-Abrams wrote:
> 
>> On Sat, 8 Sep 2001, vin wrote:
>>
>> > Gven  a file exmpl.py
>> >
>> > def foo(x,y):
>> >     return x,y;
>> >
>> > Why does the following ....
>> >
>> > module=PyImport_ImportModule("exmpl");
>> > PyRun_SimpleString("print dir(exmpl)\n");
>> >
>> > give ....
>> >
>> > Traceback (most recent call last):
>> >   File "<string>", line 1, in ?
>> > NameError: name 'exmpl' is not defined
>>
>> You have to put this line between the two:
>>
>>   PyDict_SetItemString(PyModule_GetModuleDict(), "exmpl", module);
> 
> Sigh. I meant PyImport_GetModuleDict(), of course...
> 




More information about the Python-list mailing list