[ python-Feature Requests-1190701 ] Add 'before' and 'after' methods to Strings

SourceForge.net noreply at sourceforge.net
Wed Apr 27 03:35:57 CEST 2005


Feature Requests item #1190701, was opened at 2005-04-26 20:35
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1190701&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Christopher Dunn (cxdunn)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add 'before' and 'after' methods to Strings

Initial Comment:
GNU String used to have two very useful methods,
'before' and 'after'. These are so useful I keep them
defined in an __init__.py file. (Unfortunately, I do
not know how to make them methods, instead of global
functions.)

Usage:

>>> "root.sub".before(".")
'root'
>>> "root.sub1.sub2".after("root.sub1")
'.sub2'

They work like s.split(word)[0], and s.split(word)[-1],
but they are so intuitive they ought to be part of the
interface.

I'm not sure whether they should raise exceptions on
failure, or simply return the whole string.

-cxdunn

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1190701&group_id=5470


More information about the Python-bugs-list mailing list