Re: string.upto() and string.from()

2006-03-22 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Sure, you're right I forgot about rsplit ! > I guess the negative indexes & al could be done with > > sep.join(xyz.split(sep)[:index]) For index=-1 use xyz.rsplit(sep, 1)[0] Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: string.upto() and string.from()

2006-03-22 Thread [EMAIL PROTECTED]
Sure, you're right I forgot about rsplit ! I guess the negative indexes & al could be done with sep.join(xyz.split(sep)[:index]) Thanks ! -- http://mail.python.org/mailman/listinfo/python-list

Re: string.upto() and string.from()

2006-03-22 Thread Kent Johnson
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > >>I often need to re-code for myself a small code snippet to define >>string.upto() and string.from(), which are used like : FWIW this is pretty easy to do with str.split() and rsplit(): >> >># canonical exa

Re: string.upto() and string.from()

2006-03-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I often need to re-code for myself a small code snippet to define > string.upto() and string.from(), which are used like : > > # canonical examples > > "1234456789".upto("45") > '1234' > > "123456dd9

Re: string.upto() and string.from()

2006-03-22 Thread Tim Williams (gmail)
On 22/03/06, Tim Williams (gmail) <[EMAIL PROTECTED]> wrote: > if  u"h" in u"hello, world !" and u"hello, world !".from("h"): >  return " u"hello, world !" >else:   # not really required, used for demonstration only >  return :) OK,  python allows me to code faster than I can think ( n

Re: string.upto() and string.from()

2006-03-22 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > I often need to re-code for myself a small code snippet to define > string.upto() and string.from(), which are used like : > > Nothing very complicated to make with find and rfind, but wouldn't this > be handy to have it ready in the common string

Re: string.upto() and string.from()

2006-03-22 Thread Tim Williams (gmail)
On 22 Mar 2006 06:41:32 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: I often need to re-code for myself a small code snippet to definestring.upto() and string.from(), which are used like : [snip] # if not found, return whole string> "hello, world !".upto("#") "hello, world !"> u"hello, wo

string.upto() and string.from()

2006-03-22 Thread [EMAIL PROTECTED]
I often need to re-code for myself a small code snippet to define string.upto() and string.from(), which are used like : # canonical examples > "1234456789".upto("45") '1234' > "123456dd987".from('d') 'd987' # if not found, ret