use sys.stdout.buffer only on Python3