[Python-ideas] Make all builtin functions accept None for optional arguments
Ram Rachum
ram.rachum at gmail.com
Tue Feb 4 11:45:51 CET 2014
Here is something that always annoys me.
I was going to write my own rreplace function, like this:
def rreplace(s, old, new, count=None):
return new.join(s.rsplit(old, count))
But lo and behold, I have to write it like this:
def rreplace(s, old, new, count=None):
return new.join(s.rsplit(old, count) if count is not None
else s.rsplit(old))
Why? Because the `str.rsplit` can't handle a count of `None`. That is quite
annoying.
There are many more builtin functions except `str.rsplit` that behave like
this.
What do you think about going over all such functions and making them able
to accept `None`?
Thanks,
Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140204/22841aa1/attachment.html>
More information about the Python-ideas
mailing list