Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Programming languages > Bug in string.find was: Re: Proposed PEP: New style indexing was
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
21 26th February 05:44
reinhold birkenfeld
External User
 
Posts: 1
Default Bug in string.find; was: Re: Proposed PEP: New style indexing,



Well, nobody stops you from posting this on python-dev and be screamed
at by Guido...

just-kidding-ly
Reinhold
  Reply With Quote


  sponsored links


22 27th February 02:44
terry reedy
External User
 
Posts: 1
Default Bug in string.find;



I agree in this sense: the use of any int as an error return is an
unPythonic *nix-Cism, which I believe was copied therefrom. Str.find is
redundant with the Pythonic exception-raising str.index and I think it
should be removed in Py3.

Therefore, I think changing it now is untimely and changing the language
because of it backwards.

Terry J. Reedy
  Reply With Quote
23 27th February 02:44
paul rubin
External User
 
Posts: 1
Default Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type


"Terry Reedy" <tjreedy@udel.edu> writes:

I like having it available so you don't have to clutter your code with
try/except if the substring isn't there. But it should not return a
valid integer index.
  Reply With Quote
24 27th February 02:44
terry reedy
External User
 
Posts: 1
Default Bug in string.find;


The try/except pattern is a pretty basic part of Python's design. One
could say the same about clutter for *every* function or method that raises
an exception on invalid input. Should more or even all be duplicated? Why
just this one?


Terry J. Reedy
  Reply With Quote
25 27th February 02:44
torsten bronger
External User
 
Posts: 1
Default Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type


Hallöchen!

"Terry Reedy" <tjreedy@udel.edu> writes:


Granted, try/except can be used for deliberate case discrimination
(which may even happen in the standard library in many places),
however, it is only the second most elegant method -- the most
elegant being "if". Where "if" does the job, it should be prefered
in my opinion.

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646
  Reply With Quote
26 27th February 02:45
paul rubin
External User
 
Posts: 1
Default Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type


"Terry Reedy" <tjreedy@udel.edu> writes:

Someone must have thought str.find was worth having, or else it
wouldn't be in the library.
  Reply With Quote
27 27th February 02:45
raymond hettinger
External User
 
Posts: 1
Default Proposed PEP: New style indexing, was Re: Bug in slice type


<klingon> Bah!
</klingon>

The pythonic way to handle negative slicing is to use reversed(). The
principle is that the mind more easily handles this in two steps,
specifying the range a forward direction, and then reversing it.

IOW, it is easier to identify the included elements and see the
direction of:

reversed(xrange(1, 20, 2))

than it is for:

xrange(19, -1, -2)

See PEP 322 for discussion and examples:
http://www.python.org/peps/pep-0322.html

Raymond
  Reply With Quote
28 27th February 02:46
terry reedy
External User
 
Posts: 1
Default Bug in string.find;


Well, Guido no longer thinks it worth having and emphatically agreed that
it should be added to one of the 'To be removed' sections of PEP 3000.

Terry J. Reedy
  Reply With Quote
29 27th February 02:46
steve holden
External User
 
Posts: 1
Default Bug in string.find; was: Re: Proposed PEP: New style indexing,was


Of course. But onc you (sensibly) decide to use an "if" then there
really isn't much difference between -1, None, () and sys.maxint as
a sentinel value, is there?

Which is what I've been trying to say all along.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
  Reply With Quote
30 27th February 02:47
steve holden
External User
 
Posts: 1
Default Bug in string.find; was: Re: Proposed PEP: New style indexing,


If you want an exception from your code when 'w' isn't in the string you
should consider using index() rather than find.

Otherwise, whatever find() returns you will have to have an "if" in
there to handle the not-found case.

This just sounds like whining to me. If you want to catch errors, use a
function that will raise an exception rather than relying on the
invalidity of the result.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666