You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I recently started teaching Python. I found turtle module interesting and I'm planning to use the module for deeper understanding of loop, condition, and function. I tried to simplify some turtle examples, just to show how for loop works. I cloned Turtle object, moved the clones to initial position, and cleared all Turtles before start drawing. However, clear() method did not work as I expected. Here is the code that I used.
I expected t2.clear() to clear the trace of the cloned Turtle. Instead, t2.clear() erased the trace of the original Turtle, where the trace was drawn after the cloning.
I wanted to know what is going on, so I read the definition of clear() method, and the method seemed to delete all items in self.items. Also, the source code of forward() used self.currentLineItem when drawing. So I tracked items and currentLineItem in my code. Here are the results of the tracking.
So, t2 drew lines in 3, however, because 3 is not in t2.items, t2.clear() does not delete 3. Also, t1 drew lines in 2, and, because 2 is in t2.items, t2.clear() delete 2.
I think that the items of the cloned Turtle should be [1,3] instead of [1,2] after clone() is called.
The turtle clone doc just says "Create and return a clone of the turtle with same position, heading and turtle properties." The properties section has t.position() and t.heading() methods. Turtle attributes currentLine (a list of positions), items (a list of ints?, each a line id?), currentLineItem (an int from items, the last?) are not documented. There is another undocumented attribute, drawingLineItem (an int, not in items), and likely others. Lets hope they are either copied correctly by clone or are not relevant.
Chaebin-Kim24
changed the title
bugs of clear() after clone() in turtle.py module
Unexpected behavior of clear() after clone() in turtle.py module
Nov 23, 2024
Unexpected behavior report
Unexpected behavior description:
Hello, I recently started teaching Python. I found turtle module interesting and I'm planning to use the module for deeper understanding of loop, condition, and function. I tried to simplify some turtle examples, just to show how for loop works. I cloned Turtle object, moved the clones to initial position, and cleared all Turtles before start drawing. However, clear() method did not work as I expected. Here is the code that I used.
I expected t2.clear() to clear the trace of the cloned Turtle. Instead, t2.clear() erased the trace of the original Turtle, where the trace was drawn after the cloning.
I wanted to know what is going on, so I read the definition of clear() method, and the method seemed to delete all items in self.items. Also, the source code of forward() used self.currentLineItem when drawing. So I tracked items and currentLineItem in my code. Here are the results of the tracking.
So, t2 drew lines in 3, however, because 3 is not in t2.items, t2.clear() does not delete 3. Also, t1 drew lines in 2, and, because 2 is in t2.items, t2.clear() delete 2.
I think that the items of the cloned Turtle should be [1,3] instead of [1,2] after clone() is called.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: