Crossin的编程教室
标题:
Python报错typeError: 'tuple' object is not callable
[打印本页]
作者:
Electro01
时间:
2017-8-24 13:26
标题:
Python报错typeError: 'tuple' object is not callable
class Lexicon(object):
def __init__(self):
self.directions = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back']
self.verbs = ['go', 'stop', 'kill', 'eat']
self.stops = ['the', 'in', 'of', 'from', 'at', 'it']
self.nouns = ['door', 'bear', 'princess', 'cabinet']
self.numbers = [i for i in range(10)]
def lexicon(self):
stuff = raw_input('> ')
words = stuff.split(' ')
result = self.scan(words)
def scan(self, words):
result = []
for i in words.split():
try:
if i in self.directions:
result.append(('direction', i))
elif i in self.verbs:
result.append(('verb', i))
elif i in self.stops:
result.append(('stop', i))
elif i in self.nouns:
result.append(('noun', i))
else:
i = int(i)
result.append(('number', i))
except ValueError:
result.append(('error', i))
return result
lexicon = Lexicon()
复制代码
以上是我自己码的代码
以下是报错信息:
sc:test admin$ nosetests
...EEEEEE
======================================================================
ERROR: lexicon_tests.test_directions
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 9, in test_directions
('direction', 'south')
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_verb
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 16, in test_verb
('verb', 'kill')
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_stops
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 23, in test_stops
('stop', 'in')
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_nouns
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 30, in test_nouns
('noun', 'princess')])
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_numbers
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 36, in test_numbers
('number', '91234')])
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_errors
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 42, in test_errors
('error', 'IAS')
TypeError: 'tuple' object is not callable
----------------------------------------------------------------------
Ran 9 tests in 0.094s
FAILED (errors=6)
sc:test admin$ nosetests
...EEEEEE
======================================================================
ERROR: lexicon_tests.test_directions
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 9, in test_directions
('direction', 'south')
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_verb
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 16, in test_verb
('verb', 'kill')
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_stops
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 23, in test_stops
('stop', 'in')
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_nouns
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 30, in test_nouns
('noun', 'princess')])
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_numbers
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 36, in test_numbers
('number', '91234')])
TypeError: 'tuple' object is not callable
======================================================================
ERROR: lexicon_tests.test_errors
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/admin/mystuff/test/lexicon_tests.py", line 42, in test_errors
('error', 'IAS')
TypeError: 'tuple' object is not callable
----------------------------------------------------------------------
Ran 9 tests in 0.118s
FAILED (errors=6)
复制代码
作者:
crossin先生
时间:
2017-8-24 13:46
报错信息:lexicon_tests.py 第42行
报错的代码你没有放上来吧
看起来是你的测试代码写的不对,并不是代码的报错
作者:
Electro01
时间:
2017-8-24 14:09
crossin先生 发表于 2017-8-24 13:46
报错信息:lexicon_tests.py 第42行
报错的代码你没有放上来吧
的确是测试代码的问题,解决了! 谢谢!
欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/)
Powered by Discuz! X2.5