Part 1: The Difference Between open
and with open
Basically, using with
just ensures that you don't forget to close()
the file, making it safer/preventing memory issues.
Part 2: The FileExistsError
This is an OS error and, therefore, may be OS specific. Your syntax is correct though, assuming that you want to overwrite (truncate) the previous file.
This is probably why the problem is OS-specific and most other users are unable to duplicate the issue.
However, if it's causing issues, you could try using w+
mode and it may fix the issue.
A similar issue was documented here.
EDIT: I just noticed the comment stream about teams
originally being the path. Glad it got fixed!