Fixed a bug on Python 3 when writing to stdout