我有一個我定義的類,該類當前需要2個參數self和savepath。這個類的一個方法需要2個參數,self。在該方法中,我調用了一個函數,它再次接受2個參數local_hash和filename,但是,在調用此方法後,我得到如下所述的錯誤。我認爲它與自我論證有一定的關係,但我無法弄清楚在哪裏或爲什麼。並且爲了記錄,put_nowait()是默認模塊的一種方法。我不會假設我需要發佈我使用的所有相關默認模塊的代碼。接收未知參數的類的方法
的方法:
def cache_files(self, path):
self.folder_path = path
self.md5_queue = Queue.Queue()
accepted_file_types = ['.jpg', '.png', '.gif']
self.hash_directory = os.walk(self.folder_path, topdown=True)
if self.folder_path != None:
for root, subfolders, images in self.hash_directory:
for filename in images:
try:
if filename[-4:] in accepted_file_types:
self.local_hash = hash_sum(os.path.join(root, filename))
self.md5_queue.put_nowait(filename, self.local_hash)
except IOError:
continue
print 'Directory has finished caching, exiting...'
return self.md5_queue
的DEF的run():
def run(self):
# references pickle file if available
md5_path = os.path.join(os.path.dirname(__file__), 'md5.pickle')
try:
self.md5_dict = md5_unpickler(md5_path)
except IOError:
pass
if self.hash == True:
self.cache_files(self.savepath)
else:
self.build_queue()
錯誤:
Traceback (most recent call last):
File "C:\Users\Cirno\Dropbox\CirnoCrawler\crawler.py", line 98, in run
self.cache_files(self.savepath)
File "C:\Users\Cirno\Dropbox\CirnoCrawler\crawler.py", line 84, in cache_files
self.md5_queue.put_nowait(filename, self.local_hash)
TypeError: put_nowait() takes exactly 2 arguments (3 given)
什麼'def put_nowait()'在類中? – 2011-12-31 21:38:10
'put_nowait()'是隊列模塊的一種方法。 – Cirno 2011-12-31 22:02:56
找到我的答案。 put_nowait()期待2個參數,'put_nowait(self,(tuple,here))'。不是'put_nowait(元組,在這裏)' – Cirno 2011-12-31 23:43:44