Some Python 2.1 ideas

Tino Wildenhain tino at wildenhain.de
Sun Dec 24 11:16:01 CET 2000


Hi Erno,

Erno Kuusela wrote:
> 
> >>>>> "Bob" == Bob Alexander <bobalex at home.com> writes:
> 
> [snip]
> 
> | ---- String method to remove trailing newline
> 
> i think it would be prettier and more useful to have methods
> to remove a given prefix/suffix from the beginning or the end of a
> string. maybe add optional arguments for lstrip/rstrip, or
> introduce new methods rtrim/ltrim?

You mean removing it only if it matches?
If yes, you can at least use for ltrim:

string.replace(str,begin_to_match,'',1)

if not, you can simply use <string>[len(begin_to_match):]

Regards
Tino




More information about the Python-list mailing list