This is the start of the py2cpp project. Already a simple compiler based on compiler.ast can generate a strange mixture of Python, C and C++ code. The point is that the script is actually generating code from the syntax tree. Not bad for less than a day's work.

Here is the first test code:

class aClass:
    def spam(a):
        b = 2
        for i in xrange(0,2):
            a = 2+3
        return 'eggs' #comment
a = aClass()
b = a.spam(2)
if b == 4:
    c = 1
elif 6 < b2 > 4:
    c = 2
else:
    pass

And here is the output:

class aClass:
    def spam:
        b = 2 ;
        for (i in xrange(0,2)) {
            a = (2 + 3) ;
        }
        return "eggs" ;
a = aClass() ;
b = a.spam(2) ;
if ((b == 4)) {
    c = 1 ;
}
elif ((6 < b2) && (b2 > 4)) {
    c = 2 ;
}
else {
    ;
}

The code is on cvs in src/py2cpp.leo.