readline和 readlines的区别:
1、readline:一行一行的读取文件,每次读取一行。
#使用集合来多个属性的值 import os list_student=[] with open("/Users/gaowenjing/Desktop/Student.txt",mode="r",encoding="UTF-8") as fd: current_line=fd.readline() # while current_line: temp_list=current_line.split(",") list_student.append(temp_list) current_line = fd.readline() print(list_student)
2、readlines:每次读取文件的全部行。用for 循环分别读取每一行。
#使用集合来多个属性的值 import os list_student=[] student_list=[] with open("/Users/gaowenjing/Desktop/Student.txt",mode="r",encoding="UTF-8") as fd: for line in fd.readlines(): line_temp=line.split(",") student_list.append(line_temp) print(student_list)