- 帖子
- 6
- 精华
- 0
- 积分
- 24
- 阅读权限
- 10
- 注册时间
- 2017-8-24
- 最后登录
- 2017-8-30
|
- 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)
复制代码 |
|