>>> import os
>>> dir_fd = os.open('oni.py', os.O_RDONLY)
>>> def opener(path, flags):
...     return os.open(path, flags, dir_fd=dir_fd)
...
>>> with open('oni.txt', 'w', opener=opener) as f:
...     print('This will be written to oni.txt', file=f)
...
>>> os.close(dir_fd)  # не забывайте закрыть файловый дескриптор