我在這裏遇到了一堵牆,所以我會盡我所能解釋這個問題。「'module'沒有任何屬性」當使用namedtuples時
def playGames(jobQueue, ...):
....
nextJob = jobQueue.get()
...
def runPool(fens, timesetting, ...):
...
for fen in fens:
jobQueue.put(Job(gamefen=fen, timecontrol=timesetting))
...
if __name__ == '__main__':
Job = collections.namedtuple('Job', 'gamefen timecontrol')
...
...
playGames(jobQueue, ...) # jobQueue is a multiprocess.Queue() object
運行此操作後,會引發以下錯誤。
"'module' object has no attribute 'Job'"
因此,我將Job = collections ...行移到了if name == main事件上面,它工作正常!
但是,代碼編寫的方式沒有Job = collections ...移動在我的Ubuntu系統上將工作得很好。
所以Windows7的使用python2.7.8它不使用python2.7.6它的工作 Ubuntu14使用python3.4.3工作 Ubuntu14它的工作
我必須缺少的東西在這裏...
THE FULL TRACEBACK是在這裏:
Traceback (most recent call last):
File "c:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap
self.run()
File "c:\Python27\lib\multiprocessing\process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "c:\Users\Andy\Desktop\Github\LucasZinc\Zinc.py", line 338, in play_games
_job = jobQueue.get()
File "c:\Python27\lib\multiprocessing\queues.py", line 117, in get
res = self._recv()
AttributeError: 'module' object has no attribute 'Job'
請顯示完整的錯誤信息和完整的回溯。 – BrenBarn
添加了追溯 – AndrewGrant