- Where Developers Learn, Share, & Build Careers


I'm working on Python in a difficult way, exercise 48, using nosetests to test tuples I am determined that the following types are:

  def test_directions (): assert_equal (lexicon.scan ("answer"), [('direction', 'answer']])   

However, I get the following error every time:

  ... line 5, test_directions assert_equal (lexicon.scan ("answer"), [ ('Direction', 'answer')] Type type: unbound method scan () first Should be called with a Lexicon example as a (got RR frequency instead)   

If I present just above @staticmethod "def scan (self):" I would rather This error is found:

  line 24, in the scan words = self.sentence.split () attribute error: 'str' is not an attribute of the object 'sentence'   

and the code I am testing it is below. What am I missing?

  class terminology T): def __init __ (self, sentences): self.sentence = sentences self.direction = "direction" self.verb = "verb" self. In the name of the self itself, "self.number =" number "self.number =" number "self.direction_words = ('north', 'south', 'east', 'west', 'up', 'down' ) Self.stop_words = ('the', '' ',' ',' self ',' a ',' ',' ',' ',' ',' '' A, 'A', 'A', 'A', 'A', 'It'). Self = 1 self-instructions = [] DRF scan (self): word = self-adjusting. Split () self.a = 0 While the self. A & lt; lan (words): results = words [self] A. If the result is in self: Directions_days: self.instructions.append (('direction', result)) elif Results themselves .verb_words: self.instructions.append (('verb', result)) elif results in itself. Noun_words: self.instructions.append (('noun,' result)) elif results in itself. Stop_words: self.instructions .append ('stop', results)) Self elif Test_num (results) == None: self.instructions.append (('number', 'error')) Other: self.instructions.append (('number' , Result)) self.a + = 1 return self.instructions def test_num (self, number): try: valueError: return (num) return    

< Div class = "post-text" itemprop = "text">

It looks like you're already with your string You need to paste the Lexicon object, then scan that object. In summary:

  def test_directions (): assert_equal (lexicon ("answer"). Scan (), [('direction', 'answer']])   

You can see this because the __ init __ method takes sentence as a logic, while the scan method does not contain any real Logic is not (simply self , which shows an example of an object). Due to the use of @staticmethod , this sentence (in this case, "Answer") is caused by the treatment of the example as the lexicon class, which causes clear reasons Fails for

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -