Typing arguments in python

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Wed Apr 16 12:01:13 EDT 2003


Alex Martelli <aleax at aleax.it> wrote:

>Dale Strickland-Clark wrote:
>
>> 
>> Obviously, there's a 'not' missing from the above :-(.
>
>Hmmmm, are you sure...?  This raises when the attribute is
>missing, which seems likely to be what one desires.

No. I'm being a dick. :-(

>In a case such as this, the idiom would reduce, at a minimum, to:
>
>def f(fileobj):
>    write = fileobj.write
>    # rest of function follows -- just call write('...') when needed
>
>by extracting the bound-method as the first action of the function,
>you ensure the exception happens ASAP -- *AND* you get a nice little
>performance boost in many cases too.  You can spend some of that
>boost to do a little bit more checking than the above snippets show,
>for example:
>
>def f(fileobj):
>    write = fileobj.write
>    write('')
>    # rest of function follows -- just call write('...') when needed

Way too fussy and obscure for my liking. Also, the assert is debugging
code and nicely goes away in production. 

-- 
Dale Strickland-Clark
Riverhall Systems Ltd




More information about the Python-list mailing list