Home  >  Article  >  Backend Development  >  Detailed explanation of the difference between read, readline and readlines in python

Detailed explanation of the difference between read, readline and readlines in python

黄舟
黄舟Original
2017-09-23 11:03:535310browse

The following editor will bring you a detailed discussion of the differences between python read readline readlines. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

The file object is created using the open function. The following table lists the differences between the common functions read, readline, and readlines of the file object:

1. Read the specified number of bytes from the file. If size is not given or is negative, read all.

file.read([size])

2. Read the entire line, including the "\n" character.

file.readline([size])

3. Read all lines and return the list, if sizeint> is given; 0, returns rows whose sum totals approximately sizeint bytes. The actual read value may be larger than sizeint because the buffer needs to be filled.

file.readlines([sizeint])

For example:

read

readline

readlines

The above is the detailed content of Detailed explanation of the difference between read, readline and readlines in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn