Reading a file one character at a time - section 7.2.1

Hi, Section 7.2.1. Methods of File Objects <https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects> says To read a file’s contents, call f.read(size), which reads some quantity of
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 [...]. Otherwise, at most *size* bytes are read and returned.
The problem is that it says "bytes", but in text mode, f.read(size) will return *size **characters*. It seems like this just wasn't updated since Python 2. It could be rephrased as: Otherwise, at most *size* characters (in text mode) or *size* bytes (in
binary mode) are read and returned.
By the way, the section on io.TextIOBase.read <https://docs.python.org/3/library/io.html#io.TextIOBase.read> does not have this problem. Thanks, William Andrea

Hi William,
The problem is that it says "bytes", but in text mode, f.read(size) will return size characters.
You're right, thanks for reporting! Would you like to open a pull request on https://github.com/python/cpython to fix this? If you need any help in doing so, don't hesitate to ask. (The file is here: https://github.com/python/cpython/blob/master/Doc/tutorial/inputoutput.rst) Bests, -- Julien Palard https://mdk.fr

Hi Julien, I've created a draft pull request <https://github.com/python/cpython/pull/13852>. Looks like the next step is to register on b.p.o., sign the CLA, and open a bug on b.p.o., is that correct? William On Wed, Jun 5, 2019 at 4:58 PM Julien Palard <julien@palard.fr> wrote:
Hi William,
The problem is that it says "bytes", but in text mode, f.read(size) will return size characters.
You're right, thanks for reporting! Would you like to open a pull request on https://github.com/python/cpython to fix this? If you need any help in doing so, don't hesitate to ask.
(The file is here: https://github.com/python/cpython/blob/master/Doc/tutorial/inputoutput.rst )
Bests, -- Julien Palard https://mdk.fr

Hi William! Thanks for taking the time to open a PR, welcome!
Looks like the next step is to register on b.p.o., sign the CLA, and open a bug on b.p.o., is that correct?
I added labels on your PR to avoid having to write a NEWS entry and opening an issue, we don't do them for such little changes. However the CLA is mandatory (legal thing). -- Julien Palard https://mdk.fr

I've signed the CLA and the-knights-who-say-ni have picked it up. I'm just waiting for review now :) Also, I skimmed the rest of section 7.2 and saw some other errors/omissions related to text mode vs binary mode. I'm not sure how to fix all of them, so should I open a bug on b.p.o.? On Sat, Jun 8, 2019 at 11:23 AM Julien Palard <julien@palard.fr> wrote:
Hi William!
Thanks for taking the time to open a PR, welcome!
Looks like the next step is to register on b.p.o., sign the CLA, and open a bug on b.p.o., is that correct?
I added labels on your PR to avoid having to write a NEWS entry and opening an issue, we don't do them for such little changes.
However the CLA is mandatory (legal thing).
-- Julien Palard https://mdk.fr
participants (2)
-
Julien Palard
-
William Andrea