py3-go
py3-go copied to clipboard
trafficstars
go python3 bind
python version:3.10.5python version:3.8.10 (default supper win7)
support list
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
cgo-less
install
go get github.com/aadog/py3-go
test
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))
`)
}
exception
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))
`)
}