Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
> I've never seen any student try `str(range(10))` in the repl I never suggested that students would try calling str() directly. That would be silly. They would use print(), as I'm sure many of them are already doing. After 20+ years of using Python, I still sometimes use print in the interactive interpreter when I don't need to. > they all naturally try the bare `range(10)` and they're all presented > with un-informative information. It isn't un-informative information. Its very informative, and useful, but perhaps not the information you are trying to teach your students *at that moment*. But they will have potentially decades of use of Python, long after they have learned that range() is half-open, and the long <range object [start, start+1, ..., end-2, end-1]> form is no longer necessary, and perhaps even an annoyance. (It certainly annoys *me*. The existing short form is usually better for my needs, and I think I'm more representative of the average Python coder over their career than beginners during their first few weeks.) > As for repr(range(0)) == repr(range(2, 2)) == repr(range(1, 5, -1)) I > do not consider this a bug I didn't say it was a bug. But it reduces the utility of the display, as you cannot tell the difference between any two empty range objects. And that can be important when trying to work out why your range object is unexpectedly empty. > I don't really agree that changing the repr could break code doing > `eval(repr(range(10)))`, That's not something up for debate. Whether you "really agree" or not, it is a fact that your proposed repr is not legal Python code and therefore it will break code doing eval() on it. > is it really something people do? It is a backwards-incompatible change of behaviour, therefore we must assume it will break someone's code and treat it as a major change. That's not to say that we can't change the repr, but we don't do it lightly. Personally, making a change for the sake of beginners during their first few weeks of learning the language, but inconveniences them for the remaining 95% of their career as a Python coder, does not sound like a good trade-off to me. That's why I suggest that print(range_obj) is a good compromise. Lots of beginners already do this, and for those who don't, print is a good diagnostic tool which they should be taught early. And yes, changing the __str__ is a backwards-incompatible change too, but the potential negative consequences are smaller and the work-arounds are easier. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35200> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com