[Python-ideas] Deprecate str.find

Georg Brandl g.brandl at gmx.net
Fri Jul 15 20:26:42 CEST 2011


Am 15.07.2011 19:13, schrieb Devin Jeanpierre:
> On Fri, Jul 15, 2011 at 12:38 PM, Guido van Rossum <guido at python.org> wrote:
>> This smells a bit like uncalled-for religion. Remember that readline()
>> returns an empty string at the end of the file instead of raising an
>> exception, and IMO that makes it the better API.
> 
> The last time I used file.readline was to pass to tokenize, which is
> complicated immensely by the logic necessary to support both the
> iterator protocol and the readline protocol. i.e. it has to check for
> both StopIteration _and_ the empty string, which makes it harder to
> use, forces it to contain more redundant information.

Sorry, I don't see the immense complication in

        try:
            line = readline()
        except StopIteration:
            line = ''

Of course, if the tokenize API was designed from scratch nowadays,
it would probably only accept iterables, and you'd have to make one
yourself from a file object using

    iter(fd.readline, '')

cheers,
Georg




More information about the Python-ideas mailing list