Thomas Jollans wrote: > > >> string.rstrip( [ '-dir' ] ) >> or as >> string.rstrip( '-dir' ) > > The former should certainly raise an exception. '-dir' is not a single > character ! > Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but > that's just silly. > It's silly with the example of '-dir' it's much less silly with a string like ' \t'.
The doc is rather clear about it: str.rstrip([chars]) It is marked 'chars' and not 'suffix' The textual description is even clearer: "The chars argument is not a suffix; rather, all combinations of its values are stripped:" When I asked in this grpup about a way of how to strip off a prefix I never even considered strip as a solution having read the doc before. I also think, that the functionality of strip / rstrip is useful as is. It would just be great to have functions to strip prefixes/suffixes. If these new commands were alphabetically next to the classic commands, ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for string functions would probably use the function, which is appropriate for his purpose. Breaking backwardscompatibility within python 3 might not be the best choice. >> However I wouldn't be sure, that it really reduces the amount of >> questions being asked. >> >> In order to reduce the ambiguities one had to have two distinct functions. >> If one wouldn't want to break backwards-compatibility, then the new >> names would be for stripping off prefixes / suffixes and could be >> str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes) >> >> >> I'd love to have this functionality, though I can live with importing my >> self written function. > -- http://mail.python.org/mailman/listinfo/python-list