首页 > 解决方案 > 为什么我会收到“TypeError: '_gdbm.gdbm' object is not iterable”?

问题描述

这是我第一次将“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

标签: pythondbm

解决方案


推荐阅读