goPy 是一个新的开源项目,实现了用 Go 语言来编写 CPython 扩展。
示例代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package simple import ("fmt""gopy") func example(args*py.Tuple) (py.Object, error) {fmt.Printf("simple.example: %v\n", args)py.None.Incref()return py.None, nil} func init() {methods := []py.Method{{"example", example,"example function"},} _, err := py.InitModule("simple", methods)if err != nil {panic(err)}} |
编译方法:
gopy pymodule.go
使用方法:
import simple
simple.example(“hello”, {123: True})
输出结果:
simple.example: [hello map[123:true]]
github开源项目地址:https://github.com/qur/gopy
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END












暂无评论内容