ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Python json list as json and write in json file,tkinter popup as messagebox

Python json list as json and write in json file,tkinter popup as messagebox
import uuid
import datetime
import time
import json
import tkinter as tk
import tkinter.messagebox as msgBoxclass Book():def __init__(self,id,name,isbn,comment,content,summary,title,topic):self.id=idself.name=nameself.isbn=isbnself.comment=commentself.content=contentself.summary=summaryself.title=titleself.topic=topicdef __str__(self):return f'Id:{self.id},name:{self.name},isbn:{self.isbn},comment:{self.comment},content:{self.content},summary:{self.summary},title:{self.title},topic:{self.topic}'book_list=[]arr=range(1,100001)
for a in arr:book_list.append(Book(f'{a}',f'Name_{a}',f'ISBN_{a}',f'Comment_{a}',f'Content_{a}',f'Summary_{a}',f'Title_{a}',f'Topic_{a}'))book_data=[]
for bk in book_list:dic={'id':bk.id,'name':bk.name,'isbn':bk.isbn,'comment':bk.comment,'content':bk.content,'summary':bk.summary,'title':bk.title,'topic':bk.topic}book_data.append(dic)jsonFile=f'Json_{datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")}.json'
with open(jsonFile,'a+',encoding='utf-8') as jsonWriteFile:json.dump(book_data,jsonWriteFile,indent=4)msgBox.showinfo(f'json serialization finished!',f'{datetime.datetime.now()} save {len(book_list)} items in {jsonFile}')

 

image

 

 

 

image

 

image

 

返回列表