第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

根據(jù)用戶(hù)輸入更新 JSON

根據(jù)用戶(hù)輸入更新 JSON

蕭十郎 2023-07-05 16:30:38
我想根據(jù)用戶(hù)的輸入使用 JSON 創(chuàng)建數(shù)據(jù)庫(kù)。我已經(jīng)編寫(xiě)了這段代碼,但它用新數(shù)據(jù)替換了整個(gè)文件,并且不更新現(xiàn)有的 JSON 文件。文件database.json給出的輸出為{"Employee ID": "ID2", "Employee Name": "Friendrich", "Domain": "Engineering", "Employee Type": "Permanent", "Start Date": "01.02.2020", "End Date": "28.02.2021"}import jsons_id = input('employeeID')s_name = input('employeeName')s_domain = input('domain')s_type = input('employeeType')s_from = input('start-date')s_until = input('end-date')database = {        'Employee ID' : s_id,        'Employee Name' : s_name,        'Domain' : s_domain,        'Employee Type' : s_type,        'Start Date' : s_from,        'End Date' : s_until        }with open('database.json') as json_file:    data = json.load(json_file)data.update(database)with open('database.json', 'w') as json_file:    json.dump(database, json_file)使用新輸入時(shí),json 文件應(yīng)將數(shù)據(jù)添加到現(xiàn)有文件中。所以輸出應(yīng)該是{"Employee ID": "new ID", "Employee Name": "input name", "Domain": "input domain", "Employee Type": "input type", "Start Date": "input date", "End Date": "input date"}, {"Employee ID": "ID2", "Employee Name": "Friendrich", "Domain": "Engineering", "Employee Type": "Permanent", "Start Date": "01.02.2020", "End Date": "28.02.2021"}, 我創(chuàng)建這個(gè)數(shù)據(jù)庫(kù)是為了找到具有特定過(guò)濾器的所有員工。假設(shè)所有具有工程領(lǐng)域的員工。使用 JSON 作為數(shù)據(jù)庫(kù)是一個(gè)好習(xí)慣嗎?
查看完整描述

2 回答

?
蕪湖不蕪

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊

每次保存數(shù)據(jù)時(shí)都會(huì)截?cái)辔募?br />使用“?a?”而不是“?w?”作為打開(kāi)模式。

代替

with?open('database.json',?'w')?as?json_file:
????json.dump(database,?json_file)

with?open('database.json',?'a')?as?json_file:
????json.dump(database,?json_file)


查看完整回答
反對(duì) 回復(fù) 2023-07-05
?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊

關(guān)于你的問(wèn)題,使用 sqlite3 (加上 python)來(lái)更新數(shù)據(jù)庫(kù)更容易。一探究竟!



查看完整回答
反對(duì) 回復(fù) 2023-07-05
  • 2 回答
  • 0 關(guān)注
  • 148 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)