Ask coding questions

← Back to all posts
What is an "AttributeError"?
ggigabyte (4)

https://repl.it/@ggigabyte/Turtle-drawer
Just run it and you'll see.

The program worked on the offline IDLE.

Comments
hotnewtop
ChezCoder (1605)

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

Example:

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

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

Returns:

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

Explanation:

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.

Solution:

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.