def daochu():
data2 = select("select * from cd_phone order by id desc limit 20") # 查询数据
name = time.strftime("%Y%m%d%H%M%S") # 文件名
with open(name + '.txt', 'w') as file:
for i in range(len(data2)):
times = ' ' if data2[i][4] == None else time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(data2[i][4]))
# 拼接并写入数据
file.write(str(data2[i][1]) + '----' + str(data2[i][7]) + '----' + status_text(data[i][2]) + '----' + str(times) + '----' + str(data2[i][6]) + '\n')
python导出txt文件
最新推荐文章于 2024-07-20 02:19:51 发布