[Tutor] 'str' object has no attribute 'description'

Hugo Arts hugo.yoshi at gmail.com
Sun Dec 18 23:41:39 CET 2011


On Sun, Dec 18, 2011 at 11:23 PM, Wayne Werner <waynejwerner at gmail.com> wrote:
> On Sun, Dec 18, 2011 at 4:06 PM, Russell Shackleton <rshack at xtra.co.nz>
> wrote:
>>
>> I am learning Python classes by writing an adventure game. I have
>> extracted just the relevant code. The player can look, go, drop, take,
>> inventory but not examine.
>>
>> Python produces the error message in the Player class, examine function,
>> in the first print statement.
>>
>
> It's best to give the full traceback, because it provides an awful lot of
> information.
>
> -Wayne
>

Wayne's right. Always give us a full traceback. Where the error
finally shows itself is rarely the same as where it's first started,
and a traceback can tell us that.

That said, you did a pretty good job of removing irrelevant code
(thank you!! it helps us a lot! :), and I was able to find your
particular error. It starts in this snippet:

elif action == "examine":
                       if len(cmdlist) != 2:
                           print "An examine command must be followed
by an item name."
                           continue
                       else:
                           character.examine(cmdlist[1]) # <--- right here

the problem is that cmdlist is just a list of strings. Hence
cmdlist[1] is a string as well. And strings don't have the description
attribute, hence python is complaining. What you likely meant is not
to examine not the string, but the item object with a name that equals
that string.

HTH,
Hugo


More information about the Tutor mailing list