Monday, September 16, 2013

Class Inheritance Problems In Python

I was trying to play around with classes a little the other day I ran into some problems.

I tried to call a function on a child, that calls the parent and uses the self attribute. It wasn't having it.
I got the error
AttributeError: Class Instance has no Attribute ''

After some searching I came across this post, it was a little confusing but I think I finally got it.

http://stackoverflow.com/questions/16528171/attributeerror-child-object-has-no-attribute-name

Here is an example of the result in action:


*Notice I had to do Animal.__init__(self) for the function to work. It took me quite a while to figure this one out.