- 时间:2018-11-22 整理:byzqy
python读写文本文件
1 # -*- coding: utf-8 -*- 2 3 def read_file(file): 4 with open(file, 'r') as f: 5 print(f.read()) 6 f.close() 7 8 def write_file(file): 9 with open(file, 'a') as f: 10 for i in range(10): 11 f.write(str(i) + '\n') 12 f.close() 13 14 file = 'test.txt' 15 write_file(file) 16 read_file(file)
转自:https://blog.csdn.net/u010429424/article/details/76136727