string.upto() and string.from()

Tim Williams (gmail) tdwdotnet at
Wed Mar 22 16:16:20 CET 2006

On 22 Mar 2006 06:41:32 -0800, ikshefem at <ikshefem at>
> I often need to re-code for myself a small code snippet to define
> string.upto() and string.from(), which are used like :


# if not found, return whole string
> > "hello, world !".upto("#")
> "hello, world !"
> > u"hello, world !".from("#")
> u"hello, world !"



> u"hello, world !".from("#")
u"hello, world !"

return None,  otherwise what would the difference be between it and

>u"hello, world !".from("h")
u"hello, world !"

If it returns the whole string how would you test that a returned value was
a not-found rather than a true result?

> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list