Ex49 test_subject help, please!

Hello! I’m new around here and have been learning for about two months, with varying levels of difficulty and success haha.

I’d like some help with the beginning of the ex49 tests. I’ve copied what I have below.
When I run nosetests on what I have, I get the following error:

File "C:\Users\danzi\lpthw\ex48\tests\parser_tests.py", line 10, in test_subject
    assert s1.object == "pigeon"
AttributeError: 'Sentence' object has no attribute 'object'

I have no idea what that means, and have spent several hours trying to make sure I’ve typed in in correctly and looking for answers on codestack and github, but they are all done a different way than Mr. Shaw demonstrates in the videos. I don’t know how I’m getting an attribute error; it looks like everything is correctly assigned. Could you help? Thanks all!

parser_tests.py :

from nose.tools import *
from ex48 import lexicon, parser

def test_subject():
    s1 = parser.Sentence(('noun', "cheese"),
                         ('verb', "eats"),
                         ('noun', "pigeon"))
    assert s1.verb == "eats"
    assert s1.subject == "cheese"
    assert s1.object == "pigeon"

parser.py :

class ParserError(Exception):

class Sentence(object):
    def __init__(self, subject, verb, obj):
        self.subject = subject[1]
        self.verb = verb[1]
        self.object = obj[1]

In the line for s1, you’re missing some things.

On the page for exercise 49, look at the paragraph labeled “Playing with the Parser”. Zed has an example of how it should look.

You’re missing an underscore plus the s in sentence should not be capitalized plus it needs some square brackets. The statement for s1 is using a function from the module “parser” that you’ve imported. Not the class Sentence.


This is a weird error. You’re clearly setting self.object in the __init__ but it’s not actually being set. That tells me that maybe this Sentence isn’t the one you think you’re running. That means one of a few things:

  1. You fixed this but didn’t save the file, or saved it somewhere else. That means you’re running old code.
  2. You are loading code from somewhere else on the computer.

Try putting this right before the self.object = obj[1] line:


You don’t really need to write that whole string, but the assert will cause your code to explode right there. If you get the assert bomb then you know that code is running like you expect. Be sure to really confirm it ran that and not some other assert. If it runs, then I have no idea what’s going on.

If it doesn’t run then you’re loading code from somewhere else. I’m just not sure where.

Zed, thanks for the help. You were spot on, I had the file saved under ex48 and ex48/ex48. Deleted the extra copy and it passed! I think I correctly tested the skip function, too.

Posting this late because I only now finished working through the rest of the exercise. Thanks again!

1 Like