Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Failed to import some python std libs(e.g. json) in python code and then called in go code #408

Open
always-less opened this issue Jul 30, 2018 · 0 comments

Comments

@always-less
Copy link

always-less commented Jul 30, 2018

My python code is as below

def feature1(inputJsonString):
    print inputJsonString
    import json
    import sys
    print json.dumps(1)
    return sys.version

and the go main code is as below

package main

import ... // I have imported all the package under the "$GOPATH/src/__python__" and thus "json" related libs should be imported

func main() {
    f := grumpy.NewRootFrame()
    mods, _ := grumpy.ImportModule(f, "feature1")
    fmt.Printf("mods: %v\n", mods)
    feature1, _ := grumpy.GetAttr(f, mods[0], grumpy.NewStr("feature1"), nil)
    args := f.MakeArgs(1)
    args[0] = grumpy.NewStr(`{"a": 1, "b": "I am string"}`).ToObject()
    result, err := feature1.Call(f, args, nil)
    fmt.Printf("result type: %v\n", reflect.TypeOf(result))
    fmt.Printf("result: %v\n", result.String())
    fmt.Printf("err: %v\n", err)
}

When I tried to run the go main code, and I got result like this

result: nil
err: TypeError('bad operand type for unary -: \'tuple\'',)

I found this error is raised from grumpy.ImportModule function in generated go code feature1.go but I am not clear how this error is raised. Also when I try to import some other python std libs like "sys", and it works fine.

My Golang version is go1.10.3 darwin/amd64

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant