https://github.com/aadog/py3-go
https://github.com/aadog/py3-go
go-py3 go-python less-cgo py3 python python-go python3
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aadog/py3-go
- Owner: aadog
- License: mit
- Created: 2022-07-22T15:04:39.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-22T11:48:24.000Z (over 3 years ago)
- Last Synced: 2024-06-21T15:26:39.476Z (almost 2 years ago)
- Topics: go-py3, go-python, less-cgo, py3, python, python-go, python3
- Language: Go
- Homepage:
- Size: 8.31 MB
- Stars: 17
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
### go python3 bind
* ```python version:3.10.5```
* ```python version:3.8.10 (default supper win7)```
### support list
- `cogo-less,It does not need CGO support, so the compilation speed is very fast`
- `python3 all plugin,include Native module`
- `Automatic type conversion Go to PyObject`
- `Automatic type conversion PyObject to Go`
- `import Any Python package`
- `C 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))
`)
}
```