Typing arguments in python

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Wed Apr 16 15:59:29 CEST 2003

danra at walla.co.il (Danra) wrote:

>def f(fileobj):
>    if not hasattr(fileobj,'write'):
>        raise TypeError, "Given arg must have the 'write' attribute."
>    .
>    .
>    fileobj.write('...')

You want assert, you do:

def f(fileobj):
    assert hasattr(fileobj, 'write'), 'Bang! Sort your code out.'

Dale Strickland-Clark
Riverhall Systems Ltd

More information about the Python-list mailing list