fix code_generation to the stdout

In python3, to write bytes to the stdout you have to write
in the underlying binary buffer.
See: http://docs.python.org/3.0/library/sys.html#sys.stdout