Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8f423c93
Kaydet (Commit)
8f423c93
authored
Kas 03, 2012
tarafından
Éric Araujo
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add examples for opener argument of open (#13424).
Patch by Guillaume Pratte.
üst
0167edf8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
0 deletions
+34
-0
functions.rst
Doc/library/functions.rst
+30
-0
io.rst
Doc/library/io.rst
+3
-0
ACKS
Misc/ACKS
+1
-0
No files found.
Doc/library/functions.rst
Dosyayı görüntüle @
8f423c93
...
...
@@ -935,6 +935,36 @@ are always available. They are listed here in alphabetical order.
:mod:`os.open` as *opener* results in functionality similar to passing
``None``).
The following example is an alternative implementation for opening files
for exclusive writing. If we did not have support for the ``'x'`` mode,
we could implement it with this opener::
>>> import os
>>> def open_exclusive(path, mode):
... return os.open(path, mode | os.O_CREAT | os.O_EXCL)
...
>>> filename = 'spam.txt'
>>> fp = open(filename, 'w', opener=open_exclusive)
>>> fp2 = open(filename, 'w', opener=open_exclusive)
Traceback (most recent call last):
...
FileExistsError: [Errno 17] File exists: 'spam.txt'
This other example uses the :ref:`dir_fd` parameter of the
:func:`os.open` function to open a file relative to a given directory::
>>> import os
>>> def open_relative(dirname):
... dir_fd = os.open(dirname, os.O_RDONLY)
... def opener(path, flags):
... return os.open(path, flags, dir_fd=dir_fd)
... return opener
...
>>> opener = open_relative('somedir')
>>> with open('spamspam.txt', 'w', opener=opener) as f:
... print('This will be written to somedir/spamspam.txt', file=f)
...
.. versionchanged:: 3.3
The *opener* parameter was added.
The ``'x'`` mode was added.
...
...
Doc/library/io.rst
Dosyayı görüntüle @
8f423c93
...
...
@@ -498,6 +498,9 @@ Raw File I/O
:mod:`os.open` as *opener* results in functionality similar to passing
``None``).
See the :func:`open` built-in function for examples on using the *opener*
parameter.
.. versionchanged:: 3.3
The *opener* parameter was added.
The ``'x'`` mode was added.
...
...
Misc/ACKS
Dosyayı görüntüle @
8f423c93
...
...
@@ -929,6 +929,7 @@ Michael Pomraning
Iustin Pop
Claudiu Popa
John Popplewell
Guillaume Pratte
Amrit Prem
Paul Prescod
Donovan Preston
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment