英文:
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('path to go application')
答案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(["go", "run", "file.go"]))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论