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

Suitable error when limitting the number of args

Which would be the suitable base error in Python for limiting the number of args passed in a function.

I’d like to limit it to 2 argument as follows:

def func(*args):

    if len(args) == 1:
        # Do one thing
        
    elif len(args) == 2:
        # Do another thing
    
    else:
        ## raise an error ## 

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

>Solution :

I think TypeError would be okay. This suggests the input is structurally incorrect.
Doc here

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