In order to write on a file by using a Python script, you would have to create a text file first. Example A file such as C:/logs/logs.txt should exist. Only then the following code works:
logfile=open(r"C:/logs/logs.txt",'w')
So summary.
- A text file should exist on the specified location
- Make sure you close the file before running the Python script.