Python File readlines() Method
Instance
Returns all lines in the file as a list, where each line is an item in the list object:
f = open("demofile.txt", "r") print(f.readlines())
Definition and Usage
readlines() method returns a list containing each line of the file as an item in the list.
Use the hint parameter to limit the number of returned lines. If the total number of returned bytes exceeds the specified number, no more lines will be returned.
Syntax
file.readlines(hint)
Parameter Value
Parameter | Description |
---|---|
hint | Optional. If the number of returned bytes exceeds hint Number, no more lines will be returned. The default value is -1, which means all lines will be returned. |
More Instances
Instance
If the total number of returned bytes is greater than 33, the next line will not be returned:
f = open("demofile.txt", "r") print(f.readline(33))