UnsupportedError when using class with magic methods

Hi!

I’m having an UnsupportedError where there shouldn’t be one. The code:

---- PONTO.PY ----
import math
    
class Ponto:
        def __init__(self,latitude,longitude):
            self.latitude = latitude
            self.longitude = longitude
        def __sub__(self,other):
            dy = 111300.0*(self.latitude - other.latitude)
            dlat = (self.latitude + other.latitude)/2
            dlat = math.radians(dlat)
            dx = 111300.0*math.cos(dlat)*(self.longitude - other.longitude)
            distance = math.pow(dx,2) + math.pow(dy,2)
            distance = math.sqrt(distance)
            return int(distance)

---- MAIN.PY ----
import Ponto

    p1 = Ponto.Ponto(9.645161,35.707523)
    p2 = Ponto.Ponto(9.647038,35.707614)

    distancia = p1-p2
    print(distancia)

returns the message:

  • [Thread 1 exited with exception UnsupportedError @[0000:00ED:0000:0000:0000:0000:0000:0000]](javascript:window.except(’@[0000:00ED:0000:0000:0000:0000:0000:0000]’,'Thread 1 exited with exception UnsupportedError '))*

The code works well in IDLE, so isn’t a problem with it. Can someone give me a help?

I put the class “Ponto” in a different file (Ponto.py).

(sorry if I posted this topic in wrong section)

Hi @Nysix
This is a strange error, let me know look into this and get back to you with details.
Thanks.

1 Like