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:UsersAdministrator.PC-20170627ZTZFDesktopggg.txt') line = fobj.readlines() print(line) 根据文件名称读取文件里面的内容: filename=input('enter file name:') f = open(r'C:UsersAdministrator.PC-20170627ZTZFDesktopggg.txt') allLines=f.readlines() f.close() for eachLine in allLines: print(eachLine)