This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Accept file mode "rw" to open-or-create a file and seek to the start
Type: enhancement Stage:
Components: Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ncoghlan, serhiy.storchaka
Priority: low Keywords:

Created on 2021-02-05 04:36 by ncoghlan, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg386510 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2021-02-05 04:36
After yet again trying to use "rw" to open a file in read/write mode, having it fail, and then having to look up the docs to remind myself that the correct spelling is "r+", I'm finally filing this to suggest we make the obvious "rw" spelling actually work.

Rather than making it an alias for any of the existing modes, I'd suggest that it combine the features of "r+" and "a+":

* like "r+" it would start the file pointer at the beginning of the file
* like "a+" it would create the file if it didn't exist, while leaving existing files alone
msg386533 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-02-05 17:49
Open modes "r", "r+", "w", "w+", "a", "a+" are supported by C function fopen() and similar functions in other languages. Would not "rw" be confusing? Are there fopen-like functions in other programming languages which support this mode?

Are there any examples in the stdlib which would benefit from this feature? The closest that I found is in mailbox and combines "rb+" with "wb+" and "rb", and I seen combinations of "rb+" and "xb+" in third-party code, but they are different cases.
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87299
2021-02-05 17:49:28serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg386533
2021-02-05 04:36:25ncoghlancreate