On Wed, 23 Aug 2006 08:56:54 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> But an upside is that it would enable more useful error messages, at least >> sometimes. Here's some trivial pseudo-code: >> >> def foo(a): >> assert len(a) > 10, "%s is too short" % a.__name__ >> >> y = "hello" >> foo(y) >> >> would display "AssertionError: y is too short". > > why not "a is too short" ? > > or for that matter, "x is to short" ?
These are all valid responses too. But consider that when you get an exception that says "a is too short", you often have to mentally change gears and think about where a came from and what it is called in the enclosing scope. After all, if the value of a is invalid, and the value of a is set in the enclosing scope, it makes sense to refer to "the object known locally as a" by the name it was known as when it was set. Of course, this leads to greater complexity, it still doesn't deal well with objects known by multiple names, or no name at all, and it would require a lot of overhead for something which is only of value occasionally. In other words, the downside outweighs the upside significantly. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list