Can i know how i can write obtained result to a File in python. For example, Below code snippet check for state. If it pass it prints pass otherwise fail.
if generalTools.waitAppear('State2.png', '25') == False:
testData.reportFail("Fail: TestCase Fail")
else:
testData.reportPass("PASS: TestCase Pass")
So, here i want to push result to a file instead of printing.
First, it has to check whether the file exists or not .If it exists, it has to clear the content and write to that file. If file doesn't exists. it has to create new file and it has to write. Can any1 give me some idea how i can do that.
with open('data.txt', 'w') as fout:'w'will truncate it for youExisting fileis ambiguous whether you want delete file and create new one or you want to append to a file. My suggestion is to change question to something likeHow to write result to a file (with overriding it if exists).