Re: Inheritance error: class Foo has no attribute "bar"



crystalattice wrote:
I've finally figured out the basics of OOP; I've created a basic character
creation class for my game and it works reasonably well. Now that I'm
trying to build a subclass that has methods to determine the rank of a
character but I keep getting errors.

I want to "redefine" some attributes from the base class so I can use them
to help determine the rank. However, I get the error that my base class
doesn't have the dictionary that I want to use. I've tried several things
to correct it but they don't work (the base class is called "Character"
and the subclass is called "Marine"):

*explicitly naming the Marine's attribute self.intel =
Character.attrib_dict["intel"]
*adding Character.__init__(self) to the Marine's __init__(self) method
*changing the self.intel attribute from referencing the Character's
dictionary to self (based on the assumption that since Marine is a
subset of Character, it should have it's own attrib_dict being created

Nothing seems to work; I still get the error "class Character has no
attribute "attrib_dict".

I can't see why it's saying this because Character.__init__(self) not only
has self.attrib_dict = {} but it also calls the setAttribute method
explicitly for each attribute name. If I do a print out of the dictionary
just for Character, the attributes are listed.


Without a sample of your code and the actual tracebacks you're getting
it is difficult to know what's going wrong.


Are you writing your class like this:

class Character:
def __init__(self):
# do some stuff here..

class Marine(Character):
def __init__(self):
Character.__init__(self)
# do some stuff here..

?


Peace,
~Simon

.



Relevant Pages

  • Re: Inheritance error: class Foo has no attribute "bar"
    ... character but I keep getting errors. ... I want to "redefine" some attributes from the base class so I can use them ... to help determine the rank. ... and the subclass is called "Marine"): ...
    (comp.lang.python)
  • Re: Inheritance error: class Foo has no attribute "bar"
    ... class Character has no attribute 'attrib_dict' ... expressly in the Marine subclass when I wanted to rename a dictionary ... I want to "redefine" some attributes from the base class so I can use them ... Without seeing your class definitions, it is hard to tell what you are ...
    (comp.lang.python)
  • Re: Inheritance error: class Foo has no attribute "bar"
    ... character but I keep getting errors. ... I want to "redefine" some attributes from the base class so I can use them ... to help determine the rank. ... and the subclass is called "Marine"): ...
    (comp.lang.python)
  • Re: double message box again
    ... > is operator for [distinguishing character types]? ... Suppose you create an abstract base class along ... which means that a subclass can replace it with its own ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reader feelings management OR rank your chapters OR "pre-crit"
    ... So let's say you allocate number one to a character ... But if 1 scene out'a 5 are battle, that must result in a not so high "battle ... But neither rank nor rate are the right word, ... Yes, a thriller needs to be highly thrilling, but it does not need to be ...
    (rec.arts.sf.composition)

Loading