Todd Mitchell wrote: > While you are poking around in the python plugin code can you figure > out how to add the python folder in the maps module to the > PyInitialize() sys.path so that it will be checked for modules there > automatically and first. I could not figure out how to do it from C code. (I found that feature request in the python mailing list but it seems not (yet?) implemented.) My attached patch runs the script $MAPDIR/python/events/python_init.py right after initializing the Python interpreter. The attached sample script just adds $MAPDIR/python to the end of sys.path. (I just don't know enough of Python to prepend the directory to sys.path.) Note: sys.path seems to be global to the Python interpreter. Therefore the current solution (to append to sys.path in each script) increases the path list by and by. Can you check the patch and tell me possible problems? (Or just commit it if it seems good.) -------------- next part -------------- Index: plugin/plugin_python.c =================================================================== RCS file: /cvsroot/crossfire/crossfire/plugin/plugin_python.c,v retrieving revision 1.34 diff -w -c -5 -r1.34 plugin_python.c *** plugin/plugin_python.c 18 Oct 2004 06:35:38 -0000 1.34 --- plugin/plugin_python.c 18 Oct 2004 16:46:50 -0000 *************** *** 7198,7207 **** --- 7198,7209 ---- static PyObject* CFPythonError; MODULEAPI void initCFPython() { PyObject *m, *d; int i; + FILE *scriptfile; + const char *scriptname; printf( "PYTHON - Start initCFPython.\n"); m = Py_InitModule("CFPython", CFPythonMethods); d = PyModule_GetDict(m); *************** *** 7211,7216 **** --- 7213,7228 ---- { CustomCommand[i].name = NULL; CustomCommand[i].script = NULL; CustomCommand[i].speed = 0.0; }; + + StackPosition++; + scriptname = create_pathname("python/events/python_init.py"); + scriptfile = fopen(scriptname, "r"); + if (scriptfile != NULL) + { + PyRun_SimpleFile(scriptfile, scriptname); + fclose(scriptfile); + } + StackPosition--; }; -------------- next part -------------- A non-text attachment was scrubbed... Name: python_init.py Type: text/x-python Size: 141 bytes Desc: not available Url : http://shadowknight.real-time.com/pipermail/crossfire/attachments/20041018/4b10e168/python_init.py -------------- next part -------------- _______________________________________________ crossfire-devel mailing list crossfire-devel at lists.real-time.com https://mailman.real-time.com/mailman/listinfo/crossfire-devel