虽然python是万能的,但是对于某些特殊功能,需要c语言才能完成。这样,就需要用python来调用c的代码了
具体流程:
c编写相关函数 ,编译成库
然后在python中加载这些库,指定调用函数。
这些函数可以char ,int, float, 还能返回指针。

以下示例:
通过python调用c函数,返回"hello,world 字符串"
新建c语言文件 hello.c
touch hello.c

#include <stdio.h>

char *get_str()
{
return "hello,world"
}

编译成库
gcc -o hello.so --share -fPIC hello.c

新建python脚本
touch test.py

from ctypes import *

dll = CDLL("./hello.so")
dll.get_str.restype = c_char_p
str = dll.get_str()
print(string_at(str, 11))

执行python脚本

[feng@arch python_c]$ python test.py
hello,world

最新文章

  1. Python学习笔记(二)——HelloWorld
  2. 请求WebApi的几种方式
  3. 操作系统开发系列—12.e.Makefile
  4. A-Making the Grade(POJ 3666)
  5. jsp探针
  6. 利用c++操作XML,主要是内部循环方法的使用
  7. 讨论JDK的File.equal()
  8. qt 汉化 国际化
  9. 手动搭建express框架
  10. 基于Office 365的随需应变业务应用平台
  11. P2757 [国家集训队]等差子序列
  12. Codeforces Global Round 2 Solution
  13. zabbix 邮件报警配置
  14. MySQL创建数据库时指定编码utf8mb4和添加用户
  15. 利用Flume将MySQL表数据准实时抽取到HDFS
  16. P3181 [HAOI2016]找相同字符
  17. Web接口测试-HttpClient
  18. A1055. The World&#39;s Richest
  19. ubuntu系统初始化网络及mysql配置
  20. 杭电acm习题分类

热门文章

  1. golang 并发执行函数func类型slice
  2. mongdb数据迁移导出与导入
  3. 180608-Git工具之Stash
  4. 第3章 TCP协议详解
  5. mweb test
  6. Python3 Tkinter-Place
  7. java.net.ProtocolException: Server redirected too many times
  8. 水仙花数---基于python
  9. Thunder团队第二周 - Scrum会议1
  10. c# windows service 程序