Inheritance error: class Foo has no attribute "bar"

crystalattice crystalattice at yahoo.com
Sun Jul 9 00:24:01 EDT 2006


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.

-- 
Python-based online RPG based on the Colonial Marines from "Aliens" -  
http://www.colonialmarinesrpg.com

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Python-list mailing list