如何为Go创建一个在Python解释器上运行的运行时环境?

huangapple go评论110阅读模式
英文:

how to make a runtime environment for Go to/on the Python Interpreter?

问题

所以,如果可能的话,能做到吗?就像igo(https://code.google.com/p/jgo/)那样!它为Go编程语言提供了一个完整的编译器和运行时环境,可以在Java虚拟机上运行。

如果可能的话,我需要学习或了解什么?

我想做的就是编写一个Python包,使得可以运行Python解释器!

from mypackage import Run
Run('go应用程序的路径')
英文:

so if it possible to make it? just like what igo(https://code.google.com/p/jgo/) does! it provide a complete compiler and runtime environment for the Go programming language to/on the Java Virtual Machine!

if possible! what i need to learn or know?

what i want to do is just writing a python package to make it possible to run python interpreter!

<!-- language: python -->

from mypackage import Run
Run(&#39;path to go application&#39;)

答案1

得分: 4

你可以将Go代码转换为Python字节码,但这样做没有太多意义。相同的Go程序只会运行得更慢。

你需要学习Python字节码和编写编译器。

如果你只是想从Python中编译和运行Go代码,你可以使用Python的标准库:https://stackoverflow.com/questions/89228/calling-an-external-command-in-python

from subprocess import check_output
print(check_output(["go", "run", "file.go"]))
英文:

You could translate go code into Python bytecode, but it wouldn't make a lot of sense. The same Go program would just run slower.

You'd need to learn python bytecode and writing compilers.

If you just want to compile and run Go code from Python you can use Python's standard library: https://stackoverflow.com/questions/89228/calling-an-external-command-in-python

from subprocess import check_output
print(check_output([&quot;go&quot;, &quot;run&quot;, &quot;file.go&quot;]))

huangapple
  • 本文由 发表于 2013年12月6日 17:19:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/20420166.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定