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

How to import and call function(written in python and transferred into go by grumpc) in go? #407

Open
always-less opened this issue Jul 26, 2018 · 1 comment

Comments

@always-less
Copy link

always-less commented Jul 26, 2018

As titled, the newest grumpy.ImportModule function has only 2 params while the comment has not been updated.

And ImportModule(f, "a.b") causes the initialization and entry into sys.modules of Grumpy module a and
then Grumpy module a.b instead of b. Is this a bug?

@davejohnston
Copy link

I could do with some help on this too.
Following the steps in the README.md https://github.com/google/grumpy I've done the following:

echo 'def hello(): print "hello, world"' > $GOPATH/src/__python__/hello.py

grumpc -modname=hello $GOPATH/src/__python__/hello.py > \
    $GOPATH/src/__python__/hello/module.go

I can now use grumprun to import the module in python
echo 'from hello import hello; hello()' | grumprun

This produces the output

hello, world

What I can't do is figure out how to import the module hello in a golang main and run it.
I've tried the following:

func main() {
	grumpy.ImportModule(grumpy.NewRootFrame(), "traceback")
	os.Exit(grumpy.RunMain(hello.Code))
}

This runs, but produces no output. I'm guessing I need to call the hello() method that is generated in the init() block of module.go, but I can't see how that should be done ?

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

2 participants