string.upto() and string.from()

Tim Williams (gmail) tdwdotnet at gmail.com
Wed Mar 22 10:16:20 EST 2006


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


[snip]

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


[snip]

Shouldn't

> 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: <http://mail.python.org/pipermail/python-list/attachments/20060322/578dbabb/attachment.html>


More information about the Python-list mailing list