classification
Title: Support Windows file open modes for `open` built-in function
Type: enhancement Stage:
Components: IO, Windows Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, eryksun, lukedeller1, methane, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-07-22 00:15 by lukedeller1, last changed 2021-07-22 08:21 by eryksun.

Messages (2)
msg397971 - (view) Author: Luke Deller (lukedeller1) Date: 2021-07-22 00:15
Microsoft Windows supports some extra file open modes including:
 "S" 	Specifies that caching is optimized for, but not restricted to, sequential access from disk.
 "T" 	Specifies a file as temporary. If possible, it is not flushed to disk.
 "D" 	Specifies a file as temporary. It is deleted when the last file pointer is closed

Python 2 used to allow "T" and "D" flags in the built-in `open` function (though this was not documented):
https://github.com/python/cpython/blob/2.7/Objects/fileobject.c#L214

It would be great if these flags were allowed in Python 3.

I see that Python3 implementation uses `open`/`_wopen` rather than `fopen` now.  The mapping to numeric flags for `_wopen` is shown in the documentation here:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen (search for "Equivalent oflag value")
msg397980 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-07-22 08:21
Currently you can use os.open() if you need platform-specific open flags such as Windows O_RANDOM, O_SEQUENTIAL, O_SHORT_LIVED, and O_TEMPORARY. The file descriptor can be passed to builtin open() to get a file object that owns the fd.

It might be more convenient if the os module had a function to translate an open() mode string into a combination of the flags O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_EXCL, and O_APPEND. Plus O_BINARY in Windows.
History
Date User Action Args
2021-07-22 08:21:36eryksunsetnosy: + eryksun, paul.moore, tim.golden, steve.dower, zach.ware
messages: + msg397980
components: + Windows
2021-07-22 01:28:21corona10setnosy: + corona10
2021-07-22 01:28:08corona10setversions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
2021-07-22 01:28:01corona10setnosy: + methane
2021-07-22 00:15:18lukedeller1create