写
#覆盖写 with open(f_path,'w') as f: f.write('I love programming! ') f.write('I love English too! ')
f.flush() #立即写入,不先写入缓存
#追加 with open(f_path,'a') as f: f.write('I love programming! ') f.write('I love English too! ')
读
with open(f_path) as f: for line in f: print(line)