Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign a type to a parameter in python?

I have a class named triangulo, and a class named coord. So, in a way to create a new instance of triangle, I pass three vertex like

t= triangle( V1, V2, V3)

So, for documentation, I want to write the class triangle in this way

class triangulo( object ):
   def __init__(self, a:coord, b:coord, c:coord)->None:
       """Constructor
       """
       self.A= a
       self.B= b
       self.C= c

class coord( object ):    
    def __init__( self, x, y ): 
        self.x= x
        self.y= y

But when I try to import this library I get this error

NameError: name 'coord' is not defined

So the question is: How can I make python accept vertex as a type of data?

like image 865
ArielCG Avatar asked May 05 '26 20:05

ArielCG


1 Answers

You need to declare the class before using it! so putting coord class on the top of triangulo will solve the problem

like image 87
amirmahdi nezhadshamsi Avatar answered May 08 '26 10:05

amirmahdi nezhadshamsi