change from print() to sys.stdout.write()