bug in str.startswith() and str.endswith()

Mel mwilson at the-wire.com
Fri May 27 09:03:55 EDT 2011


Terry Reedy wrote:

> To me, that says pretty clearly that start and end have to be
> 'positions', ie, ints or other index types. So I would say that the
> error message is a bug. I see so reason why one would want to use None
> rather that 0 for start or None rather than nothing for end.

If you're trying to wrap a call to startswith in a function that "looks 
like" startswith, there's no easy way to pass in the information that your 
caller wants the default parameters.  The case I ran into was

def wrapped_range (start, stop=None, span=None):
    do_some_things()
    result = range (start, stop, span)	# range doesn't(/didn't) accept this
    return result
   

Tne answer in that case was to take *args as the parameter to wrapped_range 
and count arguments to distinguish between the different calls to range. 

	Mel.



More information about the Python-list mailing list