Help with embedding fully qualified script name

Jim Wallace nospam at me.com
Sun Feb 13 22:16:29 EST 2005


I'm trying to call a method in a script file given a fully qualified file 
name, e.g. c:\myscript\test.py.  I find that PyImport_Import("test") works 
fine, with c:\myscript is set as the first item in the PYTHONPATH.

I tried PyRun_Simple and that does run my specific file, but then when I try 
to use the calls below that I used on PyImport_Import, I get a null function 
returned.  I've tried the other methods that use a FILE and they do the same 
thing.

pDict = PyModule_GetDict ( pModule );
pFunc = PyDict_GetItemString ( pDict, "MyFunction" );

I also tried doing things like creating a new module, etc. since I thought 
that may work, but suspect that I was missing some steps.

The basic flow I want to do is this, with only the first step being my 
problem.

1) Load the script file ??
2) Get the function "MyFunction" from the script (PyModule_GetDict, 
PyDict_GetItemString)
3) Call that function PyObject_CallObject

I appreciate any help since I've spent quite a bit of time searching and 
trying things.

Jim W.






More information about the Python-list mailing list