<div>It seems to me that the solution is that you should never use find and use index instead. You could even modify pylint/etc. to flag any use of find as an error.</div><div><br></div><div>That doesn't mean it should be deprecated so everyone else has to follow you. Deprecated now => removed in the future. While many can agree that warnings in the documentation about common mistakes in using APIs is a good thing, that doesn't translate into consensus that we should remove the API that might be misused. The documentation already says "The find() method should be used only if you need to know the position of sub. To check if sub is a substring or not, use the in operator."</div>

<div><br></div><div>There is *no* general solution to the problem of people misusing APIs. Even with index someone can still write</div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">

<div>if s.index(sub):</div></blockquote><div>which probably doesn't do what they were thinking. Should we remove that too?</div><div><br></div><div>Note that one reason people might prefer find over index is that exceptions constrain how you write the code:</div>

<div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>try:</div><div>    i = s.index(sub)</div><div>    do lots of stuff with s and i</div><div>except ValueError:</div>

<div>    result = 'not found'</div></blockquote><div><br></div><div>In this case the try wraps way too much code so it could catch a ValueError in the middle of 'stuff'. Here's correct code:</div><div>

<br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>try:</div><div>    i = s.index(sub)</div><div>    do_more = True</div><div>except:</div><div>    result = 'not found'</div>

<div>    do_more = False</div><div>if do_more:</div><div>    do lots of stuff with s and i</div></blockquote><div><br></div>Do you think that's better than:<div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">

<div>i = s.find(sub)</div><div>if i < 0:</div><div>    result = 'not found'</div><div>else:</div><div>    do lots of stuff with s and i</div></blockquote><div><div><br></div><font face="arial, helvetica, sans-serif">--- Bruce</font><div>

<font face="arial, helvetica, sans-serif">Follow me: <a href="http://www.twitter.com/Vroo" target="_blank">http://www.twitter.com/Vroo</a> <a href="http://www.vroospeak.com" target="_blank">http://www.vroospeak.com</a></font></div>

<div><font face="arial, helvetica, sans-serif"><br></font></div><br>
<br><br><div class="gmail_quote">On Fri, Jul 15, 2011 at 9:51 AM, Mike Graham <span dir="ltr"><<a href="mailto:mikegraham@gmail.com">mikegraham@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Fri, Jul 15, 2011 at 12:31 PM, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>
> While this would be a very good argument to make if we were currently<br>
> designing the str API, I don't think the benefits of suppressing<br>
> str.find outweight the burden of converting old code to use a different<br>
> idiom.<br>
><br>
> We could choose to write something about it in the documentation,<br>
> though.<br>
><br>
> Regards<br>
><br>
> Antoine.<br>
<br>
<br>
</div>That could be just as suitable. To be honest, I can't really see too<br>
much of a difference between a stronger note about the problems I<br>
perceive with str.find in the documentation and a note that uses the<br>
word "deprecated". There certainly wouldn't be occasion in the<br>
foreseeable future for you actually to remove str.find.<br>
<font color="#888888"><br>
Mike<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br></div>