pygor
Python to Go Regurgitator
Dr. Frederick Frankenstein: You must be Igor. [he pronounces it ee-gor.]
Igor: No, it's pronounced "eye-gor."
A Python 3 to Go transpiler, with many things to be desired. The purpose of this tool is not to do a complete
working translation from Python to Go, but to do a good first pass into "readable" Go. But there is some effort
to convert some "pythonism" into working Go (list/dict comprehension, generators, etc.) and to convert common
library calls to Go equivalents.
Note that the parser is currently targeted to Python 3.4 so some latest Python 3 additions are not supported (yet)
and are reported as parsing errors.
installation
go get -v -u github.com/raff/pygor
usage
go run pygor.go python_code.py
Usage of pygor:
-d int
Parser debug level 0-4
-ignore
ignore errors
-lines
add source line numbers
-main
generate a runnable application (main package)
-panic
panic on unknown expression, to get a stacktrace
-verbose
print statement and expressions
tests
for f in tests/*.py
do
go run pygor.go $f
done
example
original
def test():
a = 1
if a < 5:
return a + 5
return a - 5
def one():
n = 5
def two():
print(n + 3)
print(two())
converted
// generated by pygor
package def
import "fmt"
func test() {
var a = 1
if a < 5 {
return a + 5
}
return a - 5
}
func one() {
var n = 5
two := func() {
fmt.Println(n + 3)
}
fmt.Println(two())
}