Home > Article > Backend Development > CPython extension goPy written in Go language
goPy is a new open source project that implements CPython extensions written in Go language.
Sample code:
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) } }
Compilation method:
gopy pymodule.go
Usage method:
import simple
simple.example("hello", {123: True})
Output results:
simple.example: [hello map[123:true]]
github open source project address: https://github.com/qur/gopy