func pyTokenise(args *py.Tuple) (py.Object, error) { s := "" err := py.ParseTuple(args, "s", &s) if err != nil { return nil, err } parts := tokenise(s) t, err := py.NewTuple(int64(len(parts))) if err != nil { return nil, err } for i, arg := range parts { pyS, err := py.NewString(arg) if err != nil { t.Decref() return nil, err } t.SetItem(int64(i), pyS) } return t, nil }
func example(args *py.Tuple) (py.Object, error) { fmt.Printf("example.example\n") var s string var i int var o py.Object err := py.ParseTuple(args, "siO", &s, &i, &o) if err != nil { fmt.Printf("err: %s\n", err) return nil, err } l, ok := o.(*py.List) if !ok { return nil, fmt.Errorf("TypeError: wanted *py.List, not %T", o) } fmt.Printf("s: %s\n", s) fmt.Printf("i: %d\n", i) fmt.Printf("l: %v\n", l) for i, v := range l.Slice() { fmt.Printf("l[%d]: %v\n", i, v) } py.None.Incref() ret, err := py.BuildValue("siO", s, i, l) if err != nil { return nil, err } return ret, nil }