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