| Store | Cart

Check for the type of arguments

From: Fernando Saldanha <fsal...@gmail.com>
Sat, 17 Aug 2013 05:34:54 -0700 (PDT)
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
-- 
http://mail.python.org/mailman/listinfo/python-list

Recent Messages in this Thread
Fernando Saldanha Aug 17, 2013 12:34 pm
Skip Montanaro Aug 17, 2013 12:55 pm
Chris Angelico Aug 17, 2013 01:31 pm
Joshua Landau Aug 17, 2013 02:38 pm
Steven DAprano Aug 17, 2013 03:46 pm
Fernando Saldanha Aug 17, 2013 04:00 pm
Messages in this thread