My code
import turtle
turtle.forward(15)
It shows the error : partially initialized module 'turtle' has no attribute 'forward' (most likely due to a circular import)
My code
import turtle
turtle.forward(15)
It shows the error : partially initialized module 'turtle' has no attribute 'forward' (most likely due to a circular import)
Oh yeah I savved my file by turtle.py
Don't do that! Your code will not import the Python turtle.py library but rather assume your code is that library. And all the functions and methods, like forward()
will be missing.
[Edit: I misinterpreted the problem. The answer below was given on the assumption that the turtle-library only works in an object oriented way.]
The problem with your code is that you to not create an instance of the turtle class before using is. Importing a library with "import turtle" basically only is like telling you program that a library with that name exists. To use the functionality of the imported library, you first have to generate a turtle-object (which you can also name turtle, but I'm using my_turtle to clarify the difference).
import turtle
my_turtle = turtle.Turtle
my_turtle.forward(20)
So you import the turtle library, which contains a class named Turtle, and with "my_turtle = turtle.Turtle", you create an instance of that class, which is a Turtle. Mind that you also have to set a screen on which your turtle draws, using
screen = turtle.Screen
screen.exitonclick()
Additionally, you should refer to the documentation of the turtle library. Turtle is very well documented in a way that even new programmers can easily learn the basic concepts by reading the documentation: https://docs.python.org/3/library/turtle.html