为什么我会得到“TypeError:“\u gdbm.gdbm”对象不可iterable”?

2024-10-06 12:30:57 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我第一次把“dbm”模块作为一本书中练习的一部分来研究,我不明白为什么会出现这个错误

import dbm

db = dbm.open('chapt14/dbtest/captions', 'c')
db['cleese.png'] = 'Photo of John Cleese'
db['testeroni.png'] = 'Photo of Cohn Jleese'

for key in db:
    print(key, db[key])
db.close()
Traceback (most recent call last):
  File "/home/individuation/Documents/Code/ThinkPython/chapt14/dbtest/db_test.py", line 7, in <module>
    for key in db:
TypeError: '_gdbm.gdbm' object is not iterable

Tags: 模块ofkeyinimportfordbpng