-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile_readlines().py
More file actions
26 lines (18 loc) · 890 Bytes
/
File_readlines().py
File metadata and controls
26 lines (18 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Python File readlines() Method
# Example
# Return 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
# The readlines() method returns a list containing each line in the file as a list item.
# Use the hint parameter to limit the number of lines returned. If the total number of bytes returned exceeds the specified number, no more lines are returned.
# Syntax
# file.readlines(hint)
# Parameter Values
# Parameter Description
# hint Optional. If the number of bytes returned exceed the hint number, no more lines will be returned. Default value is -1, which means all lines will be returned.
# More examples
# Example
# Do not return the next line if the total number of returned bytes are more than 33:
f = open("demofile.txt", "r")
print(f.readlines(33))