import os,sys a = os.fdopen(sys.stdout.fileno(),"w") b = os.fdopen(sys.stdout.fileno(),"w") a.write("test1 ") b.write("test2 ") stdout result is test1 test2 but use general file object such as... a = open("test.txt","w") b = open("test.txt","w") a.write("test1") b.write("test2") the "test.txt" file content is test2 how to do this result to sys.stdout