Articles → Python → Reading A Text File In Python
Reading A Text File In Python
Example
Click to Enlarge
myfile = open("test.txt","r")
print(myfile.read())
Click to Enlarge
Specify The Number Of Characters In Read Function
myfile = open("test.txt","r")
print(myfile.read(10))
Click to Enlarge
Readline Function
myfile = open("test.txt","r")
print(myfile.readline())
Click to Enlarge
myfile = open("test.txt","r")
print(myfile.readline(10))
Click to Enlarge
Read Line By Line
myfile = open("test.txt","r")
for line in myfile:
print(line)
Click to Enlarge