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
ed3cd7e4
Kaydet (Commit)
ed3cd7e4
authored
Nis 15, 2013
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#13510: clarify that f.readlines() is note necessary to iterate over a file. Patch by Dan Riti.
üst
45fe62dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
15 deletions
+8
-15
io.rst
Doc/library/io.rst
+3
-0
inputoutput.rst
Doc/tutorial/inputoutput.rst
+4
-15
ACKS
Misc/ACKS
+1
-0
No files found.
Doc/library/io.rst
Dosyayı görüntüle @
ed3cd7e4
...
...
@@ -298,6 +298,9 @@ I/O Base Classes
to control the number of lines read: no more lines will be read if the
total size (in bytes/characters) of all lines so far exceeds *hint*.
Note that it's already possible to iterate on file objects using ``for
line in file: ...`` without calling ``file.readlines()``.
.. method:: seek(offset, whence=SEEK_SET)
Change the stream position to the given byte *offset*. *offset* is
...
...
Doc/tutorial/inputoutput.rst
Dosyayı görüntüle @
ed3cd7e4
...
...
@@ -300,18 +300,8 @@ containing only a single newline. ::
>>> f.readline()
''
``f.readlines()`` returns a list containing all the lines of data in the file.
If given an optional parameter *sizehint*, it reads that many bytes from the
file and enough more to complete a line, and returns the lines from that. This
is often used to allow efficient reading of a large file by lines, but without
having to load the entire file in memory. Only complete lines will be returned.
::
>>> f.readlines()
['This is the first line of the file.\n', 'Second line of the file\n']
An alternative approach to reading lines is to loop over the file object. This is
memory efficient, fast, and leads to simpler code::
For reading lines from a file, you can loop over the file object. This is memory
efficient, fast, and leads to simple code::
>>> for line in f:
... print(line, end='')
...
...
@@ -319,9 +309,8 @@ memory efficient, fast, and leads to simpler code::
This is the first line of the file.
Second line of the file
The alternative approach is simpler but does not provide as fine-grained
control. Since the two approaches manage line buffering differently, they
should not be mixed.
If you want to read all the lines of a file in a list you can also use
``list(f)`` or ``f.readlines()``.
``f.write(string)`` writes the contents of *string* to the file, returning
the number of characters written. ::
...
...
Misc/ACKS
Dosyayı görüntüle @
ed3cd7e4
...
...
@@ -1003,6 +1003,7 @@ Nicholas Riley
Jean-Claude Rimbault
Vlad Riscutia
Wes Rishel
Dan Riti
Juan M. Bello Rivas
Davide Rizzo
Anthony Roach
...
...
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