开发者

Python C API: Modify search path

开发者 https://www.devze.com 2023-03-29 08:57 出处:网络
How can I add a开发者_JAVA百科 speciific directory to the search path using the C API? And a related question: will the changes be local to the application, or is the search path global?Use PySys_GetO

How can I add a开发者_JAVA百科 speciific directory to the search path using the C API? And a related question: will the changes be local to the application, or is the search path global?


Use PySys_GetObject("path") to retrieve sys.path, then manipulate it as you would any other sequence or list. Changes will be local to the Python interpreter/VM.


You can update search path using the well-known Python code but called from within your C module:

PyRun_SimpleString(
   "import sys\n"
   "sys.path.append('/your/custom/path/here')\n"
);
0

精彩评论

暂无评论...
验证码 换一张
取 消