gopy 是一个新的开源项目,实现了用 go 语言来编写 cpython 扩展。
示例代码:
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
使用方法:
立即学习“Python免费学习笔记(深入)”;
import simple
simple.example("hello", {123: True})
输出结果:
simple.example: [hello map[123:true]]
github开源项目地址:https://github.com/qur/gopy
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号