#文件操作
def Read_File1():
#一次全部读取
with open("../txt/document.txt", 'r', encoding="utf-8") as file_object:
contents = file_object.read()
print(contents,type(contents))
file_object.close()
def Read_File2():
#逐行读取文件数据
people = []
with open("../txt/document.txt", 'r', encoding="utf-8") as file_object:
contents = file_object.readlines()
for line in contents:
people.append(line.rstrip())
print(line.rstrip(),type(line.rstrip()))
file_object.close()
print(people)
def Write_File():
with open("../txt/document.txt", 'w',encoding="utf-8") as file_object:
file_object.write("jack 18 1.7 60")
if __name__ == '__main__':
Write_File()
Read_File2()
Reading and writing python files
Guess you like
Origin blog.csdn.net/qq_44741914/article/details/114220126
Recommended
Ranking