Documentation
¶
Overview ¶
Package py provides tools to interact with Python. This package is mainly for SensorBee but can be used for other purposes.
py package depends on py/mainthread package. mainthread requires that it initializes the Python interpreter so that it can keep the main thread under its control. As a result, py package may not work with other packages which initializes Python.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is a bind of `*C.PyObject`
type ObjectFunc ¶
type ObjectFunc struct { Object // contains filtered or unexported fields }
ObjectFunc is a bind of `PyObject` used as `PyFunc`
type ObjectInstance ¶
type ObjectInstance struct {
Object
}
ObjectInstance is a bind of Python instance, used as `PyInstance`.
func (*ObjectInstance) Call ¶
Call calls `name` function. [TODO] this function is not supported named arguments
func (*ObjectInstance) CallDirect ¶
func (ins *ObjectInstance) CallDirect(name string, args []data.Value, kwdArg data.Map) (Object, error)
CallDirect calls `name` function and return `PyObject` directly. This method is suitable for getting the instance object that called method returned.
func (*ObjectInstance) CheckFunc ¶
func (ins *ObjectInstance) CheckFunc(name string) bool
CheckFunc checks if function having the name exists. It returns true when the function is found.
type ObjectModule ¶
type ObjectModule struct {
Object
}
ObjectModule is a bind of `PyObject`, used as `PyModule`
func LoadModule ¶
func LoadModule(name string) (ObjectModule, error)
LoadModule loads `name` module. The module needs to be placed at `sys.path`. User can set optional `sys.path` using `mainthread.AppendSysPath`
func (*ObjectModule) Call ¶
Call calls `name` function. This function is supported for module method of python.
func (*ObjectModule) GetClass ¶
func (m *ObjectModule) GetClass(name string) (ObjectInstance, error)
GetClass returns `name` class instance. User needs to call DecRef when finished using instance.
func (*ObjectModule) NewInstance ¶
func (m *ObjectModule) NewInstance(name string, args []data.Value, kwdArgs data.Map) ( ObjectInstance, error)
NewInstance returns 'name' constructor with named arguments.
class Sample(object): def __init__(self, a, b=5, **c): # initializing
To get that "Sample" python instance, callers use a map object as named arguments, and set `kwdArgs`, like:
arg1 := data.Map{ "a": data.Value, // ex) data.String("v1") "b": data.Int, // ex) data.Int(5) "hoge1": data.Value, // ex) data.Float(100.0) "hoge2": data.Value, // ex) data.True }
`arg1` is same as `Sample(a-'v1', b=5, hoge1=100.0, hoge2=True)`.
arg2 := data.Map{ "a": data.Value, // ex) data.String("v1") "hoge1": data.Value, // ex) data.Float(100.0) "hoge2": data.Value, // ex) data.True }
`arg2` is same as `Sample(a='v1', hoge1=100.0, hoge2=True)`, and `self.b` will be set default value (=5).
arg3 := data.Map{ "a": data.Value, // ex) data.String("v1") }
`arg3` is same as `Sample(a='v1')`, `self.b` will be set default value (=5), and `self.c` will be set `{}`
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package mainthread initializes Python interpreter and lock the goroutine to a specific OS thread so that the interpreter can keep using the same OS thread as a main thread.
|
Package mainthread initializes Python interpreter and lock the goroutine to a specific OS thread so that the interpreter can keep using the same OS thread as a main thread. |