Turtle Graphics are incompatible with gmpy

Mensanator mensanator at aol.com
Wed Aug 5 21:31:05 CEST 2009


On Aug 5, 2:19 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Wed, 5 Aug 2009 03:49 pm Mensanator wrote:
>
> > In 3.1, tracing is now a screen attribute, not a turtle atribute.
> > I have no idea why
>
> >   tooter = turtle.Turtle()
> >   tooter.tracer(False)
>
> > doesn't give me an error (I thought silent errors were a bad thing).
>
> What makes it an error? Do you consider the following an error?
>
> >>> class Test:
>
> ...     pass
> ...
>
> >>> t = Test()
> >>> t.tracer = 5

Come on, even _I_ know this:

>>> class Test:
	pass
>>> t = Test()
>>> t.tracer
Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    t.tracer
AttributeError: 'Test' object has no attribute 'tracer'
>>> t.tracer = False
>>> t.tracer
False


>
> Perhaps you mean, it's an API change you didn't know about, and you wish to
> protest that Turtle Graphics made an incompatible API change without
> telling you?

What does this mean?

>>> 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>

How did the tracer attribute appear out of thin air?
And more importantly, why, if has been deprecated and
dropped from 3.x?

>
> > Naturally, having tracing on caused my program to crash.
>
> It seg faulted or raised an exception?

Why did you snip it? Should I not refer to this as a crash?

Traceback (most recent call last):
  File "K:\user_python26\turtle\turtle_xy_Py3.py", line 95, in
<module>
    tooter.goto(the_coord)
  File "C:\Python31\lib\turtle.py", line 1771, in goto
    self._goto(Vec2D(*x))
  File "C:\Python31\lib\turtle.py", line 3165, in _goto
    nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)*self._speed))
ValueError: mpq.pow fractional exponent, inexact-root

>
> [...]
>
> > Unfortunately, that calculation of nhops is illegal if diffsq is
> > an .mpf (gmpy floating point). Otherwise, you get
>
> How does diffsq get to be a mpf?

No idea. I neglected to mention I'm using the new gmpy 1.10.
Don't know if that has any bearing.

> Are gmpy floats supposed to be supported?

Apparently not, as gmpy has only limited exponential capability.
Looks like I need to change turtle.py to use math.sqrt(diffsq)
or float(diffsq)**0.5. Or not pass turtle.py any .mpz since it
can't handle them.

>
> --
> Steven




More information about the Python-list mailing list