Python知识3 文件操作【多测师】
Python课堂 第四节课 import os file_name=input('enter file name:') fobj = open(file_name,'a') while True: aline=input("enter a line('.' to quit ):") if aline !='.': fobj.write('%s%s'%(aline,os.linesep)) else: break fobj.close() fobj = open(r'C:\Users\Administrator.PC-20170627ZTZF\Desktop\ggg.txt') line = fobj.readlines() print(line) 根据文件名称读取文件里面的内容: filename=input('enter file name:') f = open(r'C:\Users\Administrator.PC-20170627ZTZF\Desktop\ggg.txt') allLines=f.readlines() f.close() for eachLine in allLines: print(eachLine)