我正在使用shelve来附加并添加到词典中,但它不起作用

时间:2014-10-08 10:14:09

标签: python python-3.x shelve

import shelve
name = input('Please enter your name: ')
reg = input(Please enter the registration plate: ')
speed = input(Please enter the speed: ')
Dictionary = {name:{reg:speed}}

db = shelve.open('Data')
db['Stuff'].append(Dictionary)
db.close

f = shelve.open('Data', 'r')
print(f['Stuff'])
f.close()

我不确定如何附加字典'Stuff'。如果有人可以告诉我如何使用shelve附加字典,因为我没有任何线索。

1 个答案:

答案 0 :(得分:1)

import shelve
name = input('Please enter your name: ')
reg = input('Please enter the registration plate: ')
speed = input('Please enter the speed: ')
Dictionary = {name:{reg:speed}}

db = shelve.open('Data')
db['Stuff'].append(Dictionary)
db.close

f = shelve.open('Data', 'r')
print(f['Stuff'])
f.close()