Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15340049
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: Python/Ruby

2008-12-15 16:12:12

使用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]
阅读(2191) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~