function argument dependent on another function argument?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Jan 19 04:31:04 CET 2009


On Sun, 18 Jan 2009 22:28:04 +0000, Steven D'Aprano wrote:

> Built-ins rarely accept None as a sentinel, slice() being a conspicuous
> exception. This is sometimes a nuisance when writing wrappers:
> 
> def my_find(S, sub, start=None, end=None):
>     """Like string.find() only with pre-processing.""" pre_process()  #
>     stub for something complicated if end is None and start is None:
>         return S.find(sub)
>     elif end if None:
>         return S.find(sub, start)
>     else:
>         return S.find(sub, start, end)

Typical.

As of Python 2.6, string.find accepts None as sentinels. All my 
beautiful, beautiful code made obsolete!!! *wink*


-- 
Steven



More information about the Python-list mailing list