string.find first before location

Gary Wessle phddas at yahoo.com
Tue May 2 18:36:31 EDT 2006


"Serge Orlov" <Serge.Orlov at gmail.com> writes:

> Peter Otten wrote:
> > Gary Wessle wrote:
> >
> > >> These days str methods are preferred over the string module's functions.
> > >>
> > >> >>> text = "abc abc and Here and there"
> > >> >>> here_pos = text.find("Here")
> > >> >>> text.rfind("abc", 0, here_pos)
> > >> 4
> > >>
> > >> Peter
> > >
> > > and what about when python 3.0 is released and those depreciated
> > > functions like find and rfind are not supported. is there another
> > > solution which is more permanent?
> >
> > I think the functions may go away, the methods will stay; so I'm confident
> > the above will continue to work.
> 
> find and rfind methods are in danger too. AFAIR they are to be replaced
> by partion and rpartition methods. People who are worried about future
> can continue to use index and rindex

except with index and rindex, if the search string is not present,
they return a 
[
Traceback (most recent call last):
ValueError: substring not found
]

ps. is there a online doc or web page where one enters a method and it
returns the related docs?




More information about the Python-list mailing list