Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Dice Roller Project Breakdown

Why is this resulting in an error?

[GCC 5.4.0 20160609] on linux                                                          
Type "help", "copyright", "credits" or "license" for more information.                 
>>> import dice                                                                        
>>> d6 = dice.D6()                                                                     
Traceback (most recent call last):                                                     
  File "<stdin>", line 1, in <module>                                                  
  File "/home/treehouse/workspace/yatzy/dice.py", line 15, in __init__                 
    super().__init(sides=6, value=value)                                               
AttributeError: 'super' object has no attribute '_D6__init'                            
>>>                 

Why am I getting this error here is my code

     import random


class Die:
    def __init__(self, sides=2, value=0):
        if not sides >= 2:
            raise ValueError("Must have at least 2 sides")
        if not isinstance(sides, int):
            raise ValueError("Must be a whole number")
        self.value = value or random.randint(1, sides)


class D6(Die):
    def __init__(self, value=0):
        super().__init(sides=6, value=value)

please help me as I cannot move forward with the Die class until this Error is fixed.Thanks for any help you can give! :)

2 Answers

boi
boi
14,242 Points

Read the error message carefully, it's pointing you directly to the problem

Traceback (most recent call last):                                                     
  File "<stdin>", line 1, in <module>                                                  
  File "/home/treehouse/workspace/yatzy/dice.py", line 15, in __init__                 
    super().__init(sides=6, value=value)                                               
AttributeError: 'super' object has no attribute '_D6__init' # look here πŸ‘ˆ

The error message is suggesting that something is wrong with your super() method on line 15.

 super().__init(sides=6, value=value) # problem here πŸ‘ˆ

πŸ‘‡Correct way

super().__init__(sides=6, value=value) # missing double underscore

ok thank you so much