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
397bb248
Kaydet (Commit)
397bb248
authored
Ock 12, 2016
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#26001: mention in the tutorial that files in binary mode expect bytes, not str.
üst
f418db2e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
inputoutput.rst
Doc/tutorial/inputoutput.rst
+8
-7
No files found.
Doc/tutorial/inputoutput.rst
Dosyayı görüntüle @
397bb248
...
...
@@ -271,10 +271,11 @@ The rest of the examples in this section will assume that a file object called
``f`` has already been created.
To read a file's contents, call ``f.read(size)``, which reads some quantity of
data and returns it as a string or bytes object. *size* is an optional numeric
argument. When *size* is omitted or negative, the entire contents of the file
will be read and returned; it's your problem if the file is twice as large as
your machine's memory. Otherwise, at most *size* bytes are read and returned.
data and returns it as a string (in text mode) or bytes object (in binary mode).
*size* is an optional numeric argument. When *size* is omitted or negative, the
entire contents of the file will be read and returned; it's your problem if the
file is twice as large as your machine's memory. Otherwise, at most *size* bytes
are read and returned.
If the end of the file has been reached, ``f.read()`` will return an empty
string (``''``). ::
...
...
@@ -315,11 +316,11 @@ the number of characters written. ::
>>> f.write('This is a test\n')
15
To write something other than a string, it needs to be converted to a string
first
::
Other types of objects need to be converted -- either to a string (in text mode)
or a bytes object (in binary mode) -- before writing them
::
>>> value = ('the answer', 42)
>>> s = str(value)
>>> s = str(value)
# convert the tuple to string
>>> f.write(s)
18
...
...
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