Home  >  Article  >  Backend Development  >  CPython extension goPy written in Go language

CPython extension goPy written in Go language

高洛峰
高洛峰Original
2016-10-18 11:40:281799browse

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn