简体   繁体   English

如何为Python解释器转到/上创建运行时环境?

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

so if it possible to make it? 所以,如果有可能吗? just like what igo( https://code.google.com/p/jgo/ ) does! 就像igo( https://code.google.com/p/jgo/ )一样! it provide a complete compiler and runtime environment for the Go programming language to/on the Java Virtual Machine! 它为Go虚拟机上的Go编程语言提供了完整的编译器和运行时环境!

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! 我想要做的只是编写一个python包,使其可以运行python解释器!

from mypackage import Run
Run('path to go application')

You could translate go code into Python bytecode, but it wouldn't make a lot of sense. 您可以将代码转换为Python字节码,但它没有多大意义。 The same Go program would just run slower. 同样的Go程序只会运行得更慢。

You'd need to learn python bytecode and writing compilers. 你需要学习python字节码和编写编译器。

If you just want to compile and run Go code from Python you can use Python's standard library: Calling an external command in Python 如果您只想从Python编译和运行Go代码,您可以使用Python的标准库: 在Python中调用外部命令

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM