[Python-ideas] Deprecate str.find
M.-A. Lemburg
mal at egenix.com
Mon Jul 18 10:41:58 CEST 2011
Raymond Hettinger wrote:
> I just remembered one other thought on the subject.
>
> Usually, when Python introduces a method such as .index()
> that raises an exception for the not-found case, there
> are immediate requests for variants that don't raise exceptions:
>
> dict.pop(key, default)
> dict.get(key, defalut)
> next(iterable, default)
> getattr(obj, attr, default)
> re.match() --> None or matchobject
>
> People seem to hate wrapping try/except around simple calls.
Indeed, because for simple things, you don't want to clutter
up your code with lots of nested try-excepts.
It also has to do with performance: exceptions should only be
used for exceptional situations.
Not finding a sub-string in some line read from a log file
is not an exceptional situation. In fact, it's most likely
the common case.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Jul 18 2011)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list