Is there anything in python that can replicate the functionality of freopen() in C or C++? To be precise, I want to replicate the functionality of:
freopen(\
If you're working on *nix platform, you can write your own freopen.
freopen
def freopen(f,option,stream): import os oldf = open(f,option) oldfd = oldf.fileno() newfd = stream.fileno() os.close(newfd) os.dup2(oldfd, newfd) import sys freopen("hello","w",sys.stdout) print "world"