Skip to content

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

Closed

Description

@alanjds

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

Activity

  1. alanjds commented on Sep 2, 2018

    @alanjds
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    importedImported from google/grumpy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions