assertions to validate function parameters

Matthew Wilson matt at tplus1.com
Thu Jan 25 11:54:05 EST 2007


Lately, I've been writing functions like this:

def f(a, b):

    assert a in [1, 2, 3]
    assert b in [4, 5, 6]

The point is that I'm checking the type and the values of the
parameters.

I'm curious how this does or doesn't fit into python's duck-typing
philosophy.

I find that when I detect invalid parameters overtly, I spend less time
debugging.

Are other people doing things like this?  Any related commentary is
welcome.

Matt

-- 
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles



More information about the Python-list mailing list