0
votes

my code in python:

import turtle


    arikany = turtle.turtle()   


    arikany.bgcolor("black")
    arikany.pensize(2)
    arikany.speed(0)

    for i in range (20):
        for colours in ["red","magenta","cyan","yellow","grey"]:
            arikany.color(colours)
            arikany.circle(100)
            arikany.left(100)
            arikany.forward(95)
            arikany.right(345)
            arikany.backward(58)

    turtle.done()

The code gives me the error:

Traceback (most recent call last): File "F:/py/spirograph.py", line 5, in arikany = turtle.turtle() AttributeError: module 'turtle' has no attribute 'turtle'

3
Hey Noah, you referenced question is about naming the own file like the imported module, while this one is called 'spirograph.py'. Though the errorclass is the same, the origin is different. Renaming his file won't help him, right? - Aiyion.Prime

3 Answers

1
votes

You are trying to create an Instance of the class Turtle from the module turtle. Capitalization is crucial in this case.

The line should be something like this:

arikany = turtle.Turtle()

ps.: Its generally preferable in python3 to use the syntax from turtle import Turtle in order to explicitely import what you need.

Your line would then look like this:

arikany = Turtle()
0
votes

You should always focus at capitalisation of the words: arikany = turtle.Turtle

So,you are making an instance of the class Turtle,which is located inside of the module turtle. And the first letter of every word in a class is always in capital case

0
votes

Above all, check if you have done the common mistake of naming your file as turtle.py

if you do so, it imports your file and not the actual turtle library. So rename your file and check. If it doesn't work, other technical corrections suggested previous messages need to be checked. :)