Ask coding questions

← Back to all posts
What is an "AttributeError"?
ggigabyte (4)
Just run it and you'll see.

The program worked on the offline IDLE.

ChezCoder (1605)

An attribute error is when an attribute doesn't exist in an object.


class object:
    attrOne = "Hello "
    attrTwo = "World"

print( object.attrOne + object.attrTwo + object.thisAttrDoesntExist)


Traceback (most recent call last):
File "<stdin>", line 5, in <module>
AttributeError: type object 'object' has no attribute 'thisAttrDoesntExist'


This is because in the example, we never declared thisAttrDoesntExist. We only declared attrOne and attrTwo. Calling thisAttrDoesntExist from the class object would return an AttributeError as the attribute doesn't exist.


To solve this problem, we need to change the example a bit:

class object:
    attrOne = "Hello "
    attrTwo = "World"
    thisAttrDoesntExist = " It exists!"

print( object.attrOne + object.attrTwo + object.thisAttrDoesntExist)

Solved Result:

Hello World It exists!

Final Explanation:

It works because the class named object now has the attribute declared. It now exists. So now the name is a bit deceiving isn't it?

ChezCoder (1605)

@ggigabyte So basically what i mean is to change line 46 to:

t_program = input('Turtle ControlPanel\n' + istruzioni + '\n> ')

EDIT: "\n" means newline.