Check for the type of arguments

Fernando Saldanha fsaldan1 at gmail.com
Sat Aug 17 08:34:54 EDT 2013


I am new to Python, with some experience in Java, C++ and R.

Writing in other languages I usually check the type and values of function arguments. In the Python code examples I have seen this is rarely done. 

Questions:

1) Is this because it would be "unpythonic" or just because the examples are not really production code?

2) If I still want to check the type of my arguments, do I

a) use type() or is instance() to check for type?

b) use assert (I guess not), raise a ValueError, or sys.exit()? 

(I noticed that raising a ValueError does not stop execution when I am running the Interactive Interpreter under PTVS, which I find inconvenient, but it does stop execution when running the code non-interactively.)

Thanks.

FS



More information about the Python-list mailing list