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

Serhiy Storchaka storchaka at gmail.com
Mon Sep 3 12:06:14 EDT 2012


On 03.09.12 16:29, 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.

Or you can use new dir_fd argument for same reason (or for performance).

for root, dirs, files, rootfd in os.fwalk(topdir):
     def opener(file, flags):
         return os.open(file, flags, dir_fd=rootfd)
     for name in files:
         with open(name, "r", opener=opener) as f:
             ...





More information about the Python-list mailing list