# README
<<<<<<< HEAD
A Golang runtime Python plugin library
Introduction
This library is a Golang plugin library that allows executing Python code within a Golang runtime. It is based on the execjs library, which provides a way to execute JavaScript code within a Golang runtime.
Requirement
The environment variable PATH
must contain the path to the Python executable.
Install
You can install the goExecPy
library using the following command:
go get -u github.com/qmdemon/goExecPy
Usage
You can use the Eval
method to get the value of an expression, and the Compile
method to compile a Python code block and call it. Here's an example:
output, err := execjs.Eval(`"Hello " + "World"`)
if err != nil {
log.Fatal(err)
}
fmt.Println(output)
When using the Compile
method, it is important to ensure that the Python code block is indented correctly.
And here's an example of using the Compile
method:
c, _ := execjs.Compile(`
def add(x, y):
return x + y
`)
output, err := c.Call("add", 1, 2)
if err != nil {
log.Fatal(err)
}
fmt.Println(output)
More usage examples can be found in the execpy_test.go
file.
Please note that the returned value is of type interface{}
, so you may need to perform type assertions when using the returned value. For example:
output.(string) //This will convert the value to string type
output.([]interface{}) //This will convert the value to slice type
Thanks to
- execjs for providing the basic implementation of executing JavaScript code within a Golang runtime. ======= A Golang runtime Python plugin library
origin/master