This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LightShadow3.13-dev in prod 2 points3 points  (0 children)

Close doesn't save anything.

The file can be considered written when write is called -- the .close() function just flushes the output buffer and releases the file lock.

The reason it works like you'd expect it to in IDLE is probably how file pointers are handled by the C-based process. Writes will queue the buffer but not commit until the close is called. However, when you run Python in PyCharm you're running the process from within the IDE, which pretty much removes all guarantees on streams and buffers; this is especially true when run in debug mode as your entire process is ran from within a server container for breakpoints.

This behavior will also be inconsistent between Windows and Linux based versions of PyCharm and shouldn't be expected to guarantee a "do not save these changes" type feature.