标签:imp == amp 数据 alt lin sleep open rtu
# -*- 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}
标签:imp == amp 数据 alt lin sleep open rtu
原文地址:https://www.cnblogs.com/python-kp/p/12085024.html