Why python automatically returns the number of characters when writing a file

I recently noticed that when I have the following code:

File = "/dir/to/file"
Content = "abcdefg"

with open(File,"a") as f:
    f.write(Content)

I got "7" as the output, and this is the number of characters in the variable "Content". I don’t remember how I saw it (I used to use ipython notepad, but this time I did it in the python environment in the shell) and I wonder if I did something wrong. My python version: Python 3.3.3. Thank you for your help.

+4
source share
1 answer

As always, this behavior is normal for most implementations .write(); see also base I / O classes .

for instance io.RawIOBase.write

, b, .

io.TextIOBase.write

s .

IO - , (OS ) , open. , - "" "", .

+3

Source: https://habr.com/ru/post/1674504/


All Articles