use sys.stdout.write instead of print to avoid the trailing '\n'