Feature Requests item #1190701, was opened at 2005-04-26 20:35 Message generated for change (Comment added) made by rhettinger 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 ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2005-04-28 00:15 Message: Logged In: YES user_id=80475 I'm -1 on expanding the string API for something so easily coded with existing primitives: >>> s = "root.sub" >>> t = "." >>> s[:s.find(t)] 'root' >>> s = "root.sub1.sub2" >>> t = "root.sub1" >>> s[s.find(sep)+len(sep):] 'sub1.sub2' ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1190701&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com