##open将操作系统发起请求,操作系统完成请求, # f = open('old.txt','r',encoding = 'utf-8') # res = f.read() # print(res) # f.close() # f = open('old.txt','r',encoding = 'utf-8') # res = f.readline()##读取一行 # print(res) # f.close() ##读完文件之后必须要关闭,否则文件将一直保存在操作系统中 ##执行以下操作可以在打开文件之后,自动将文件关闭 # with open('old.txt','r',encoding = 'utf-8') as f: # res = f.read() # print(res) # pass # f = open('old.txt','w',encoding = 'utf-8') # f.write('111 ') # f.write('222 ') # f.writelines(['a ','b ','c '])##表示的是可以写入多行 # f.close()