python version:3.10.5python version:3.8.10 (default supper win7)
cogo-less,It does not need CGO support, so the compilation speed is very fastpython3 all plugin,include Native moduleAutomatic type conversion Go to PyObjectAutomatic type conversion PyObject to Goimport Any Python packageC function is registered to python, painless interaction
go get github.com/aadog/py3-go
func main(){
PyImport_AppendInittab("_test", func() *PyObject {
m := CreateModule("_test", "aa")
m.AddFunction("add", func(a, b int) int {
return a + b
})
return m.AsObj()
})
cpy3.Py_SetProgramName(os.Args[0])
cpy3.Py_SetPythonHome("./")
cpy3.Py_Initialize()
cpy3.PyRun_SimpleString(`
import _test
print(_test.Call('add',1,2))
`)
}
func main(){
PyImport_AppendInittab("_test", func() *PyObject {
m := CreateModule("_test", "aa")
m.AddFunction("add", func(a, b int) int {
py3.PyErr_SetString(py3.UserException(),"raise exception")
return a + b
})
return m.AsObj()
})
cpy3.Py_SetProgramName(os.Args[0])
cpy3.Py_SetPythonHome("./")
cpy3.Py_Initialize()
cpy3.PyRun_SimpleString(`
import _test
print(_test.Call('add',1,2))
`)
}