Generating Python Code that almost compiles