Typing arguments in python

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Wed Apr 16 16:04:47 CEST 2003


Dale Strickland-Clark <dale at riverhall.NOTHANKS.co.uk> wrote:

>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.'

Obviously, there's a 'not' missing from the above :-(.
-- 
Dale Strickland-Clark
Riverhall Systems Ltd




More information about the Python-list mailing list