-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile_readline().py
More file actions
33 lines (23 loc) · 812 Bytes
/
File_readline().py
File metadata and controls
33 lines (23 loc) · 812 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
26
27
28
29
30
31
32
# Python File readline() Method
# Example
# Read the first line of the file "demofile.txt":
f = open("demofile.txt", "r")
print(f.readline())
# Definition and Usage
# The readline() method returns one line from the file.
# You can also specified how many bytes from the line to return, by using the size parameter.
# Syntax
# file.readline(size)
# Parameter Values
# Parameter Description
# size Optional. The number of bytes from the line to return. Default -1, which means the whole line.
# More examples
# Example
# Call readline() twice to return both the first and the second line:
f = open("demofile.txt", "r")
print(f.readline())
print(f.readline())
# Example
# Return only the five first bytes from the first line:
f = open("demofile.txt", "r")
print(f.readline(5))