The following is a summary of how to read TXT files in Python. It has a good reference value and I hope it will be helpful to everyone. Come and take a look together
Method 1:
<span style="font-size:14px;">#read txt method one f = open("./image/abc.txt") line = f.readline() while line: print line line = f.readline() f.close() </span>
Method Two:
#read txt method two f = open("./image/abc.txt") for line2 in open("./image/abc.txt"): print line2
##Method Three:
#read txt method three f2 = open("./image/abc.txt","r") lines = f2.readlines() for line3 in lines: print line3
How to read file names and generate lists using python
Read csv with python File and put the file into a list example explanation
The above is the detailed content of How to read TXT files in Python. For more information, please follow other related articles on the PHP Chinese website!