Python Forum
beginner - object has no attribute
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beginner - object has no attribute
#1
Hi everyone,

I am working my way through the python for kids book and one of the challenges requires me to create a class to make a giraffe dance - I know,I know it's sounds silly but what can I say ;-)

The problem is in the last line. Can someone please explain why I am getting this error?

Thank you all. Also, sorry if the indentation gets messed up I am new to the forums.

============================================================

AttributeError: 'Giraffes' object has no attribute 'dance'

============================================================

class Animals:
    def breath(self):
        print('breathing')

    def move(self):
        print('moving')

    def eat_food(self):
        print('eating')


class Mammals(Animals):
    def feed_young_with_milk(self):
        print('feeding young')


class Giraffes(Animals):

    def eat_leaves_from_trees(self):
        print('eating leaves')


class Giraffes(Mammals):

    def left_foot_forward(self):
        print('left foot forward')

    def right_foot_forward(self):
        print('right foot forward')

    def left_foot_back(self):
        print('left foot back')

    def right_foot_back(self):
        print('right foot back')


def dance(self):
    self.left_foot_forward()
    self.right_foot_forward()
    self.left_foot_back()
    self.right_foot_back()


reginald = Giraffes()
reginald.dance()
Reply
#2
the problem is that lines 38-42 need to be indented one level to be part of class Girrafes with definition starting from line 23.
Also note that this class Girrafes effectively overwrite the class Girrafes defined on lines 17-20, i.e. your Girrafes does not have method eat_leaves_from_tress()
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Hi Buran,

Thank you for the quick reply. Indenting like you suggested made the code run perfectly.
Also, I am sorry for the missing formatting. It will not happen again.

Have a great day :-)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,731 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,914 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 747 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,386 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,670 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  WebDriver' object has no attribute 'find_element_by_css_selector rickadams 3 5,930 Sep-19-2022, 06:11 PM
Last Post: Larz60+
  'dict_items' object has no attribute 'sort' Calli 6 4,516 Jul-29-2022, 09:19 PM
Last Post: Gribouillis
  AttributeError: 'numpy.ndarray' object has no attribute 'load' hobbyist 8 7,139 Jul-06-2022, 10:55 AM
Last Post: deanhystad
  AttributeError: 'numpy.int32' object has no attribute 'split' rf_kartal 6 4,419 Jun-24-2022, 08:37 AM
Last Post: Anushka00
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 4,901 Apr-27-2022, 09:27 AM
Last Post: Anldra12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020