Turtle Graphics are incompatible with gmpy

Gregor Lingl gregor.lingl at aon.at
Wed Aug 5 19:56:50 CEST 2009


Mensanator schrieb:
>> It didn't form 2.5 to 2.6 (at least not intentionally). But with the
>> indroduction of the TurtleScreen class and the Screen class/object
>> (singleton) a few of the turtle methods were also implemented as screen
>> methods and as turtle methods declared deprecated (see docs of Python
>> 2.6). These deprecated turtle methods do not occur as turtle methods any
>> more in Python 3.x.
> 
> More info.
> 
> Yes, there is no tracer attribute...when the object is created.
> 
> But watch this (Python 3.1):
> 
>>>> import turtle
>>>> tooter = turtle.Turtle()
>>>> tooter.tracer
> Traceback (most recent call last):
>   File "<pyshell#2>", line 1, in <module>
>     tooter.tracer
> AttributeError: 'Turtle' object has no attribute 'tracer'
>>>> tooter.hideturtle()
>>>> tooter.speed('fast')
>>>> turtle.update()
>>>> turtle.tracer
> <function tracer at 0x013E0ED0>
> 
> Now, after setting hide, speed, update, a tracer exists.

No,

 >>> import turtle
 >>> turtle.tracer
<function tracer at 0x013CFE40>
 >>> help(turtle.tracer)
Help on function tracer in module turtle:

tracer(n=None, delay=None)
     Turns turtle animation on/off and set delay for update drawings.

     Optional arguments:
     n -- nonnegative  integer
     delay -- nonnegative  integer

     If n is given, only each n-th regular screen update is really 
performed.
     (Can be used to accelerate the drawing of complex graphics.)
     Second arguments sets delay value.)

     Example:
     >>> tracer(8, 25)
     >>> dist = 2
     >>> for i in range(200):
             fd(dist)
             rt(90)
             dist += 2

 >>>

The reason for this is, that the turtle module (the new one as well as 
the old one) has a vers special design: The methods of class Turtle are 
also available as functions (which are in fact methods calls of an 
anonymous turtle). The same holds for the methods of TurtleScreen.

The intention behind this design is that you can use the module in an 
OOP way as well as with procedural programming (especially for beginners).

When using objects I normally use

from turtle import Turtle, Screen
screen = Screen()
# that creates  singleton object, the screen the turtle acts on
and I create as many turtles as I need from the Turtle class

So turtle.tracer() doesn't make sense anymore


> Is that supposed to happen? That explains why there was no error
> when I set the turtle attribute instead of the screen attribute.

You do not 'set the turtle attribute', you call the tracer function of 
the turtle module

> And, of course, setting the turtle attribute accomplishes nothing,
> as actual tracing is controlled by the screen attribute as you say.
> 
>> Among them is the tracer method, which in fact does not control single
>> turtle objects but all the turtles on a given screen.
>>
>> So there is an icompatibility beween 2.6 and 3.x
>>
>> But as far as I have understood, this doesn't concern the problem
>> reported by mensator.
> 
> Only that the problem is hidden when tracing is off, as the nhops
> variable is never evaluated when trace is off.

Nevertheless I'd like to see a working Python 2.5 version of your script.

Regards,
Gregor



More information about the Python-list mailing list