The opener parameter of Python 3 open() built-in

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Sep 3 21:13:09 EDT 2012


On Mon, 03 Sep 2012 15:29:05 +0200, Christian Heimes wrote:

> Am 03.09.2012 14:32, schrieb Marco:
>> Does anyone have an example of utilisation?
> 
> The opener argument is a new 3.3 feature. For example you can use the
> feature to implement exclusive creation of a file to avoid symlink
> attacks.
> 
> import os
> 
> def opener(file, flags):
>     return os.open(file, flags | os.O_EXCL)
> 
> open("newfile", "w", opener=opener)


Why does the open builtin need this added complexity? Why not just call 
os.open directly? Or for more complex openers, just call the opener 
directly?

What is the rationale for complicating open instead of telling people to 
just call their opener directly?


-- 
Steven



More information about the Python-list mailing list