pickle.dump遇到RuntimeError:超过最大递归深度(以cmp为单位) [英] pickle.dump meet RuntimeError: maximum recursion depth exceeded in cmp
问题描述
我注意到它可能是由beautifulsoup或递归数据结构引起的.但是,导致错误的数据结构似乎没问题:
I have noticed that it may be caused by beautifulsoup or recursive data structure. however, the data structure that cause error seems no problem:
class Movie:
def __init__(self, name="", dscore=0, mscore=0, durl="", murl=""):
self.name = name
self.dscore = float(dscore)
self.mscore = float(mscore)
self.durl = durl
self.murl = murl
def __str__(self):
return unicode(self.name) + u' / ' + unicode(self.dscore) + u' / ' + unicode(self.mscore) \
+ u' / ' + unicode(self.durl) + u' / ' + unicode(self.murl)
引起问题的语句是:
DataDict['MovieInfo'] = MovieInfo
和
pickle.dump(DataDict, f, True)
以下是功能:
def SaveData():
global LinkUrlQueue
global MovieSet
global MovieInfo
global LinkUrlSet
global MovieUrlQueue
DataDict = {}
DataDict['LinkUrlSet'] = LinkUrlSet
DataDict['MovieSet'] = MovieSet
#DataDict['MovieInfo'] = MovieInfo
DataDict['LinkUrlQueue'] = LinkUrlQueue
DataDict['MovieUrlQueue'] = MovieUrlQueue
f = open('MovieInfo.txt', 'wb')
for item in MovieInfo:
f.write(item.__str__().encode('utf8') + '\n'.encode('utf8'))
f.close()
try:
print 'saving data...'
f = open('spider.dat', 'wb')
pickle.dump(DataDict, f, True)
f.close()
except IOError as e:
print 'IOError, error no: %d' % e.no
print 'saved to spider2.dat'
pickle.dump(DataDict, open('spider2.dat', 'wb'))
time.sleep(10)
我完整的源代码:
spider.py: http://paste.ubuntu.com/7149731/
spider.py: http://paste.ubuntu.com/7149731/
fetch.py: http://paste.ubuntu.com/7149732/
fetch.py: http://paste.ubuntu.com/7149732/
您可以下载并运行.
此外,欢迎提出任何编码风格建议
Besides, welcome any coding style suggestions
推荐答案
嗯...我终于自己解决了这个问题...
Well... I finally solve the problem by myself...
此问题的原因是,泡菜无法处理BEAUTIFULSOUP !!!通常,它无法处理html解析器.
The reason for this problem is that pickle cannot handle BEAUTIFULSOUP!!! Generally, it cannot handle html parser.
我意识到,当将参数传递给函数时,我应该将其转换为str()或unicode()然后进行赋值,而不是将其保留为beautifulsoup对象...
I realize that when passing arguments into my functions, I should convert them into str() or unicode() then do assignments, instead of remaining them as beautifulsoup objects...
谢谢大家〜
这篇关于pickle.dump遇到RuntimeError:超过最大递归深度(以cmp为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!