使用python批量造测试数据
Posted 南山散人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用python批量造测试数据相关的知识,希望对你有一定的参考价值。
# -*- coding:utf-8 -*- import json import os import time class Virtual_Data: def __init__(self): self.data1 = 0 self.data2 = 0 self.data3 = 0 self.json = {} def json_file(self,num): fp = open("data.txt","a") while self.data1 <= num and self.data2 <= num and self.data3 <= num: now_time = time.localtime(time.time()) timestamp = time.strftime("%Y-%m-%d %H:%M:%S",now_time) self.json = {"data1":("num"+"_"+str(self.data1)),"data2":self.data2,"data3":self.data3,"timestamp":timestamp} self.data1 += 1 self.data2 += 1 self.data3 += 1 fp.writelines(json.dumps(self.json)+os.linesep) time.sleep(1) fp.close() if __name__ == "__main__": Data = Virtual_Data() Data.json_file(10)
执行结果:
{"timestamp": "2019-12-23 15:46:48", "data1": "num_0", "data3": 0, "data2": 0}
{"timestamp": "2019-12-23 15:46:49", "data1": "num_1", "data3": 1, "data2": 1}
以上是关于使用python批量造测试数据的主要内容,如果未能解决你的问题,请参考以下文章