• 时间: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)
View Code

相关文章:

  • 2021-10-07
  • 2021-09-13
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2021-07-29
猜你喜欢
  • 2021-06-25
  • 2021-08-02
  • 2021-04-05
  • 2021-05-05
  • 2022-02-06
相关资源
相似解决方案