Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52623
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-08-17 05:34 -0700 |
| Message-ID | <185a0a88-9515-43e6-ae65-73d86b0299e7@googlegroups.com> (permalink) |
| Subject | Check for the type of arguments |
| From | Fernando Saldanha <fsaldan1@gmail.com> |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Check for the type of arguments Fernando Saldanha <fsaldan1@gmail.com> - 2013-08-17 05:34 -0700 Re: Check for the type of arguments Skip Montanaro <skip@pobox.com> - 2013-08-17 07:55 -0500 Re: Check for the type of arguments Chris Angelico <rosuav@gmail.com> - 2013-08-17 14:31 +0100 Re: Check for the type of arguments Joshua Landau <joshua@landau.ws> - 2013-08-17 15:38 +0100 Re: Check for the type of arguments Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-17 15:46 +0000 Re: Check for the type of arguments Fernando Saldanha <fsaldan1@gmail.com> - 2013-08-17 09:00 -0700
csiph-web