Files
llgo/py/_demo/callpy/call.go
2024-05-11 06:23:05 +08:00

20 lines
385 B
Go

package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
)
func main() {
py.Initialize()
py.SetProgramName(*c.Argv)
math := py.ImportModule(c.Str("math"))
sqrt := math.GetAttrString(c.Str("sqrt"))
sqrt2 := sqrt.CallOneArg(py.Float(2))
c.Printf(c.Str("sqrt(2) = %f\n"), sqrt2.FloatAsDouble())
sqrt2.DecRef()
sqrt.DecRef()
math.DecRef()
py.Finalize()
}