本文将简单介绍如何基于os库用python打开/新建/读取/写入文件的操作
之前简单介绍过:基于os库用python批量重命名文件
# open / read 'r' # f = open('text','r') # content = f.read() # print(content) # f.close() # # write 'w' # f = open('text','w') # f.write("dajidali") # f.close() # 写入----》相当于新建文件 f = open('hongda','w') f.write("jiang") f.close() # with 用 with open('hongda','r') as f1,open('text','w') as f2: content = f1.read() f2.write(content) print(content) # copy # read write
更多精彩内容