Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106575
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Checking function's parameters (type, value) or not ? |
| Date | 2016-04-06 14:29 +0100 |
| Message-ID | <mailman.131.1459949361.32530.python-list@python.org> (permalink) |
| References | <57050a05$0$4546$426a34cc@news.free.fr> <ne32v4$sfl$1@ger.gmane.org> |
On 06/04/2016 14:07, ast wrote: > Hello > > I would like to know if it is advised or not to test > a function's parameters before running it, e.g > for functions stored on a public library ? > > Example: > > def to_base(nber, base=16, use_af=True, sep=''): > > assert isinstance(nber, int) and nber >= 0 > assert isinstance(base, int) and base >= 2 > assert isinstance(use_af, bool) > assert isinstance(sep, str) and len(sep) == 1 > > tbc > > With these tests, you are sure that the function to_base is > well used. But it slows down the program. > Without, python interpreter may crash later in the function > or worse provide a meaningless result. > > What library designers do ? > Please see http://ftp.dev411.com/t/python/python-list/13bhcknhan/when-to-use-assert -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Checking function's parameters (type, value) or not ? "ast" <nomail@com.invalid> - 2016-04-06 15:07 +0200
Re: Checking function's parameters (type, value) or not ? Chris Angelico <rosuav@gmail.com> - 2016-04-06 23:27 +1000
Re: Checking function's parameters (type, value) or not ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-06 14:29 +0100
Re: Checking function's parameters (type, value) or not ? "ast" <nomail@com.invalid> - 2016-04-06 16:18 +0200
Re: Checking function's parameters (type, value) or not ? "ast" <nomail@com.invalid> - 2016-04-06 19:49 +0200
Re: Checking function's parameters (type, value) or not ? Steven D'Aprano <steve@pearwood.info> - 2016-04-07 02:30 +1000
csiph-web