f = 'file.txt'
#覆盖原有内容
with open(f,'w') as file:
file.write('hello')
#自动创建 file2.txt
with open('file2.txt','w') as file2:
file2.write('hello')
#不覆盖原有内容,在末尾继续添加
with open(f,'a') as file:
file.write('python\n')
file.write('hello\n')
文件写入
最新推荐文章于 2022-12-12 10:54:29 发布