This is a creation in Article, where the information may have evolved or changed.
Go 1.5 is released, which contains a feature: you can compile and build a dynamic-link library, and the resulting. So file can be loaded and invoked by Python. Here's an example:
Write a go file first main.go:
package mainimport"C"//export Sumfuncintint { return a + b}func main() {}
Then compile go build -buildmode=c-shared -o sum.so main.go
, get one sum.so
and one sum.h
. You can then invoke the functions in the go code with the following Python code Sum()
:
#!/usr/bin/env pythonimport ctypeslib = ctypes.CDLL('./sum.so')print lib.Sum(711)
With this mechanism in theory, you can use go to build more useful python modules.
Reference:
https://blog.filippo.io/building-python-modules-with-go-1-5/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.