我正在尝试以JSON格式转换Python对象列表。
这是我的程序:
import nxppy
import time
import json
begin_clock = time.time()
class student: # OBJECT GIVING FIRST AND LAST NAME, iDCARD AND STATUT
def __init__(self, name, idCard, present):
self.name = name
self.idCard = idCard
self.etat = None
class_TS4 = []
class_TS4.append(student('MOURETON Etienne', '4DC3A150', None))
class_TS4.append(student('METZINGER Axel', 'F9702401', None))
class_TS4.append(student('GIROUX Aurélien', '49D6BC68', None))
class_TS4.append(student('LAHCENE Zacharie', 'F3D54AD9', None))
with open('datas.json', 'w') as f:
f.write(json.dumps(class_TS4, f, indent=4))
mifare = nxppy.Mifare()
while True:
try:
uid = mifare.select()
for student in class_TS4:
if (uid == student.idCard) and not(uid in present):
student.etat = True
if begin_clock <= begin_clock + 300:
student.etat = Présent
elif begin_clock + 300 < begin_clock <= begin_clock + 600:
student.etat = Retard
elif begin_clock + 600 < begin_clock:
student.etat = Absent
elif begin_clock + 660 <= begin_clock:
f.delete(datas.json)
except nxppy.SelectError:
pass
我的目标是将其转换为阅读JSON在网页中感谢的JavaScript。
我创建的JSON文件将由JavaScript页面连续读取。
并且正如您所看到的,我正在更改continue中的某些属性状态,因此我希望JSON文件不断实现。 您认为有可能吗?如何 ?
谢谢!