Fixed printing to stream for python 3