python 3.9
#! python
# -*- coding:utf-8 -*-
import random
import time
f = open("test_data_v1.csv", "w", encoding='utf-8')
ret = f.write("id,a,b,c,d,e,f,een")
for num in range(1, 12000):
timeval = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
number = random.randint(1, 22)
backNumber = random.randint(0, 8)
operator = "姜**"
operatorCode = "02"
if num % 4 == 0:
operator = "楠**"
operatorCode = "F03"
elif num % 3 == 0:
operator = "李**"
operatorCode = "F04"
ret = f.write(str(num) + "," + str(number) + "," + str(backNumber) + "," + timeval + "," + operator + "," + operatorCode + ",婉**,B01n")
f.close()
print("关闭文件成功!")
上万条非常快。
技术点
python 写 txt 文件
python 写 txt utf-8 编码文件
python 写 txt ansi 编码文件
循环
if 分支判断
整数转字符串
字符串拼接



