0
下面的鍵值是我的代碼中,我在貨架Python的死鎖錯誤 - 正在嘗試從貨架
def updateRecord(db, form):
if not 'key' in form:
fields = dict.fromkeys(fieldnames, '?')
fields['key'] = 'Missing key input'
else:
key = form['key'].value
if key in db:
record = db[key]
else:
from person import Person
record = Person(name='?',age='?')
for field in fieldnames:
setattr(record, field, eval(form[field].value))
db[key] = record
fields = record.__dict__
fields['key'] = key
return fields
更新記錄時,我正在嘗試從貨架的價值我收到此錯誤
>>> import shelve
>>> db = shelve.open('class-shelve')
>>> db['sue'].name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/shelve.py", line 121, in __getitem__
f = StringIO(self.dict[key])
File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in __getitem__
return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
File "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap
return function(*_args, **_kwargs)
File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in <lambda>
return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
KeyError: 'sue'
有什麼見解發生了什麼?
做一個打印'db'來查看字典的內容。我的猜測是'sue'不會是一個關鍵 – karthikr
目前還不清楚你的問題是什麼。第一個代碼段與第二個代碼段有什麼關係? – martineau