Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:
Thought experiment: Suppose someone proposed, "math.log(x) should take an optional default argument because it is inconvenient to a catch a ValueError if the input is non-positive". Or more generally, what if someone proposed, "every function in Python that can raise a ValueError should offer a default argument." One could imagine a use case for both of these proposals but that doesn't mean that the API extensions would be warranted. Also, ISTM the analogy to min() and max() is imperfect. Those aren't descriptive statistics. For min() and max() we can know a priori that a probability is never lower than 0.0 or greater than 1.0 for example. Lastly, in common cases where the input is a sequence (rather than just an iterator), we already have a ternary operator to does the job nicely: central_value = mean(data) if data else 'unknown' For the less common case, a try/except is not an undue burden; after all, it is a basic core language feature. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39094> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com