Skip to content

Instantly share code, notes, and snippets.

@gopher1980
Created September 25, 2019 03:48
Show Gist options
  • Save gopher1980/587ed95609dd790887544d3cb9901b5a to your computer and use it in GitHub Desktop.
Save gopher1980/587ed95609dd790887544d3cb9901b5a to your computer and use it in GitHub Desktop.
package main
/*
#cgo pkg-config: python-3.7
#define PY_SSIZE_T_CLEAN
#include <Python.h>
int run (const char * code) {
return PyRun_SimpleString(code);
}
*/
import "C"
import "fmt"
func main() {
C.Py_Initialize();
defer C.Py_Finalize()
e := C.run(C.CString(`
import time
def multiply(a,b):
c = 0
for i in range(0, a):
c = c + b
return c
print(multiply(2,3))
print('OK!!')
`))
fmt.Println(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment