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
a66bb0a7
Kaydet (Commit)
a66bb0a7
authored
Tem 16, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#3388: add a paragraph about using "with" for file objects.
üst
0a34baf1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
inputoutput.rst
Doc/tutorial/inputoutput.rst
+10
-0
No files found.
Doc/tutorial/inputoutput.rst
Dosyayı görüntüle @
a66bb0a7
...
@@ -348,6 +348,16 @@ attempts to use the file object will automatically fail. ::
...
@@ -348,6 +348,16 @@ attempts to use the file object will automatically fail. ::
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in ?
ValueError: I/O operation on closed file
ValueError: I/O operation on closed file
It is good practice to use the :keyword:`with` keyword when dealing with file
objects. This has the advantage that the file is properly closed after its
suite finishes, even if an exception is raised on the way. It is also much
shorter than writing equivalent :keyword:`try`\ -\ :keyword:`finally` blocks::
>>> with open('/tmp/workfile', 'r') as f:
... read_data = f.read()
>>> f.closed
True
File objects have some additional methods, such as :meth:`isatty` and
File objects have some additional methods, such as :meth:`isatty` and
:meth:`truncate` which are less frequently used; consult the Library Reference
:meth:`truncate` which are less frequently used; consult the Library Reference
for a complete guide to file objects.
for a complete guide to file objects.
...
...
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