sbinet / go-python

naive go bindings to the CPython2 C-API
Other
1.53k stars 138 forks source link

Is there a way to call function with key-word parameters? #30

Closed gnani-g closed 8 years ago

gnani-g commented 8 years ago

Tried a few ways. Even the following doesn't seem to work.

    // arguments
    _a := python.PyTuple_New(1)
    python.PyTuple_SET_ITEM(_a, 0, python.PyString_FromString(`test.mp3`))

    // keyword arguments
    _kw := python.PyDict_New()
    python.PyDict_SetItem(_kw, python.PyString_FromString(`v2_version`), python.PyInt_FromLong(3))

    // pack arguments
    _args := python.PyTuple_New(2)
    python.PyTuple_SET_ITEM(_args, 0, _a)
    python.PyTuple_SET_ITEM(_args, 1, _kw)

    // ID3 is a callable
    id3 := ID3.CallObject(_args)
    if id3 == nil {
        panic("failed")
    }
sbinet commented 8 years ago

could you give 595aa16 a try? see this example for instructions: https://github.com/sbinet/go-python/blob/kw-args/tests/kw-args/main.go

gnani-g commented 8 years ago

@sbinet, The func Call works with and without arguments. Thanks.