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(\
This should help:
import sys def freopen(filename, mode): if mode == "r": sys.stdin = open(filename, mode) elif mode == "w": sys.stdout = open(filename, mode) # ---- MAIN ---- freopen("input.txt", "r") freopen("output.txt", "w")