Skip to content

Instantly share code, notes, and snippets.

@gucio321
Created February 1, 2023 19:43
Show Gist options
  • Save gucio321/ca95078b270fa6153d89184ee6e7ea3d to your computer and use it in GitHub Desktop.
Save gucio321/ca95078b270fa6153d89184ee6e7ea3d to your computer and use it in GitHub Desktop.
Simple example of GO code running Python 3.11 (works at leas on Fedora 37)
package main
// #cgo pkg-config: python3-embed
// #include <Python.h>
import "C"
import (
"unsafe"
)
func main() {
pycodeGo := `
import sys
for path in sys.path:
print(path)
`
defer C.Py_Finalize()
C.Py_Initialize()
pycodeC := C.CString(pycodeGo)
defer C.free(unsafe.Pointer(pycodeC))
C.PyRun_SimpleString(pycodeC)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment