'How To save output in python [duplicate]

I have a problem with this line

    print(Fore.RED+'NOT Found: '+url ,file=open('output.txt','w'))

I need to save the request to this output but it's not working

res = requests.get(url)
        if payload in res.text:
           print(Fore.GREEN +'Found   -->','   ' , f"{url}" + Fore.RESET)
           
        else :
            print(Fore.RED+'XSS NOT Found: '+url ,file=open('output.txt','w'))


Solution 1:[1]

Your problem is,

file=open('output.txt','w')

you use "w" parameter in your function."w" parameter deletes post information and overwrites current information all the time. If you want to append data to file, you should use

file=open('output.txt','a')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cesebe27