Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alanjds opened this issue Aug 21, 2018 · 1 comment
Labels
imported Imported from google/grumpy

Comments

@alanjds
Copy link

alanjds commented Aug 21, 2018

google#408 opened by @always-less on Jul 30

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

@alanjds alanjds added the imported Imported from google/grumpy label Aug 21, 2018
@alanjds
Copy link
Author

alanjds commented Sep 2, 2018

@always-less This was fixed by @corona10 on #5 and commented on #3.

Will close, as the provided example now works. Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported Imported from google/grumpy
Projects
None yet
Development

No branches or pull requests

1 participant