f = read(‘xxx‘) f.read() f.readline() #此处读取时,光标已经到文件最后,则此处读取的值为空
自动关闭文件的方式:
with open(‘file‘,‘w‘) as f: f.write(‘asdf‘) with open(‘file1‘,‘w‘) as f1, open(‘file2‘,‘w‘) as f2 f1.write(‘asdf‘) f2.write(‘ghjkl‘)
原文:https://www.cnblogs.com/yangjingxuan/p/11695491.html