0
点赞
收藏
分享

微信扫一扫

Python逐行写入

参考 Python逐行写入 - 云+社区 - 腾讯云

# -*-coding:utf-8-*-
import os

# 写之前,先检验文件是否存在,存在就删掉
if os.path.exists("dest.txt"):
os.remove("dest.txt")

# 以写的方式打开文件,如果文件不存在,就会自动创建
file_write_obj = open("dest.txt", 'w')
var = "adfss"
file_write_obj.writelines(var)
file_write_obj.write('\n')
file_write_obj.close()

举报

相关推荐

0 条评论