Use multiple output stream in python?
What I am going to do is to create multiple output steams in a python function, and refer them as 1 , 2 , 3 .....: In test.py : def main(): ... print >>fd1, 'words1' print >>fd2, 'words2' print >>fd3, 'words3' ... Redirect it while using: python test.py 1>1.txt 2>2.txt 3>3.txt The content of these files: 1.txt -> words1 2.txt -> words2 3.txt -> words3 The question is, how to create those fd1 , fd2 , fd3 ? Added: I have used this: outfiles = {} for _ in range(3): fd = os.dup(1) outfiles[fd] = os.fdopen(fd, 'w') def main(): for no in outfiles: print >>outfiles[no], "foo" print >>outfiles[no],