I have a script which uses open() to create multiple files. All files are created successfully and it seems that there are no problems, but when attempting to run res.py, it crashes displaying following error:
File "C:\Users\Mirac\Python\res.py", line 38
SyntaxError: Non-UTF-8 code starting with '\xd7' in file C:\Users\Mirac\Python\res.py on line 38, but no encoding declared;
When opening file through IDLE, I get 'Specify file encoding' window:
The file's encoding is invalid for Python 3.x.
IDLE will convert it to UTF-8.
What is current encoding of the file?
This is line 38 of res.py:
print("Configuration file updated.")
So, can I set encoding to file during creation, something like this:
open("res.py", "w").encoding("UTF-8")
with open("res.py", "a") as file:
file.write("File contents here")
If not, how can I fix this problem?