Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading