使用c语言调用python内置函数--开发python帮助小程序--hpy
#include
#include "Python.h"
int main(int argc, char** argv)
{
char buf[512];
if (argc != 2) {
printf("luther.gliethttp提示:请使用py cmd查询帮助命令!\n");
return 0;
}
Py_Initialize();
if (!Py_IsInitialized())
return -1;
sprintf(buf, "help('%s')", argv[1]);
PyRun_SimpleString(buf);
}
1.安装python和对应c开发库
luther@gliethttp:~$ sudo apt-get install python2.5
luther@gliethttp:~$ sudo apt-get install python2.5-dev
2.编译程序
luther@gliethttp:~$ gcc luther_gliethttp_ptyhon.c -o hpy -I/usr/include/python2.5 -L/usr/lib/python2.5 -lpython2.5
luther@gliethttp:~$ sudo cp hpy /usr/local/bin
luther@gliethttp:~$ hpy dir
Help on built-in function dir in module __builtin__:
dir(...)
dir([object]) -> list of strings
Return an alphabetized list of names comprising (some of) the attributes
of the given object, and of attributes reachable from it:
No argument: the names in the current scope.
Module object: the module attributes.
Type or class object: its attributes, and recursively the attributes of
its bases.
Otherwise: its attributes, its class's attributes, and recursively the
attributes of its class's base classes.
(END)
3.好了python的help程序开发完成了,嘿嘿[luther.gliethttp]
阅读(2240) | 评论(0) | 转发(0) |