我正在尝试将我爬入的一些站点放入搁架,但搁架不接受任何站点对象。它会接受列表、字符串、元组,你有什么,但是一旦我放入一个站点对象,当我尝试获取搁置的内容时它就会崩溃
所以当我像这样填满我的架子时:
def add_to_shelve(self, site):
db = shelve.open("database")
print site, site.url
for word in site.content:
db[word] = site.url #site.url is a string, word has to be one too
shelve.open("database")['whatever']
完美运行。
但如果我这样做:
def add_to_shelve(self, site):
db = shelve.open("database")
print site, site.url
for word in site.content:
db[word] = site #site is now an object of Site
shelve.open("database")['whatever']
出现此错误消息的错误:
AttributeError: 'module' object has no attribute 'Site'
我完全被难住了,奇怪的是,pythondocs 也没有太多信息。他们所说的只是搁置中的键必须是字符串,但值或数据可以是“任意对象”