[docs] [issue12760] Add create mode to open()

Amaury Forgeot d'Arc report at bugs.python.org
Wed Aug 24 23:19:03 CEST 2011


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

> - os.open followed by os.fdopen is easy: it isn't that easy to get
> the incantation right (the pure Python open() in _pyio is 70 lines
> of code), especially if you want the file object to have the right
> "name" attribute

What if we can override the inner call to os.open()?
For example, io.open() could grow an additional argument "fd_opener" which defaults to the equivalent of os.open.

Then creation mode can be expressed like this:
    open(filename, 'w',
         fd_opener=lambda path, mode: os.open(path, mode|os.O_CREAT)
Another use case with openat (see #12797):
    open(filename,
         fd_opener=lambda path, mode: os.openat(fd, path, mode)

----------
nosy: +amaury.forgeotdarc

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12760>
_______________________________________


More information about the docs mailing list