I am recording output of my script in a 2 different files, Dailydata.txt and historicData.txt. I was hoping that I need to just stdout in 2 different files like below,
sys.stdout = open('historicData.txt', 'a+') sys.stdout = open('Dailydata.txt', 'r+') But, it directs output to one file only.
So I redirected my output to DailyData.txt first and then write it in HistoricData.txt
with open(file_path + 'HistoricDaily.txt', 'r') as fread, open(file_path + 'FidelityHistoric.txt', 'a+') as fwrite: fread_lines = fread.readlines() for i in fread_lines: fwrite.write(i) What happens here is, every time I run the script, it writes the current run number say HistoricData.txt contains 1 2 3 4 and DailyData.txt contains 5. When I run my script, DailyData.txt will contain 6, it instead of copying the 6, script copies 5. If I run it again, it will copy 6 and not 7.
My script is like,
class MyClass: stdout = open('historicData.txt', 'a+') try: # my code Selenium stuff except: # my code finally: # copy data to HistoricData here What I am trying to achieve here is script should copy the same data from DailyData in HistoricData
Redirect the data in 2 different files at the same time.
Any help will be appreciated.