# python call go
- go 文件添加导入
import "C" - go 文件在需要导出的函数上添加注释
//export run - 执行构建
go build -buildmode=c-shared -o test.so test.go - python 文件 使用 CDLL 导入 so
CDLL('./utils/test.so').run
utils/test.go
1 | package main |
test.py
1 | import time |
import "C"//export rungo build -buildmode=c-shared -o test.so test.goCDLL('./utils/test.so').runutils/test.go
1 | package main |
test.py
1 | import time |