> > Greg Wilson: > > if "abbc"[-1] is "c", and if > > "abbc".replace("b", "x", 1) is "axbc", then shouldn't > > "abbc".replace("b", "x", -1) be "abxc" (i.e. negative > > numbers replace the *last* occurrences of the value)? > > Same argument for "split", etc. > Guido van Rossum: > Dubious hypergeneralization. Greg Wilson: Do you have an editor macro set up yet to generate that phrase? :-) > Guido van Rossum: > The thing is that this parameter, > called maxsplit, is not really an index -- it's a count. Greg Wilson: Understood; I'm asking whether changing its name and interpretation (in a way that doesn't break any existing code) would be worthwhile: >>> path = "/some/long/path/to/file.html" >>> main, parent, file = path.split("/", -2) >>> main "/some/long/path" >>> parent "to" >>> file "file.html" > > Greg Wilson: > > Turns out that "abbc".replace("b", "x", -1) is "axxc" > > (i.e. negative arguments are ignored). I would have > > expected this to raise a ValueError, if anything. Is > > there a reason for this behavior? Greg Wilson again: Question still stands --- if these are counts, then shouldn't negative values raise exceptions? Thanks, Greg
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4