15.07.2017, 18:33, "Chris Angelico" <ros...@gmail.com>:
> On Sun, Jul 16, 2017 at 10:12 AM, Jeff Walker <jeff.walke...@yandex.com> 
> wrote:
>>  The first problem is that there is no direct access to the components that 
>> make up the error in some of the standard Python exceptions.
>>
>>      >>> foo
>>      Traceback (most recent call last):
>>          File "<stdin>", line 1, in <module>
>>      NameError: name 'foo' is not defined
>>
>>  If you need access to the name, you must de-construct the error message. To 
>> get direct access to the name, it would need to be passed to the exception 
>> when raised. Why wasn't that done?
>
> Because it normally isn't needed. Can you give an example of where
> NameError could legitimately be raised from multiple causes?

For me it generally occurs when users are using Python to hold their actual 
data. Python can be used as a data format in much the same way JSON or Yaml. 
And if the end user is familiar with Python, it provides many nice benefits 
over the alternatives. I tend to use it in this fashion a great deal, 
particularly for configuration information. In these case, it would be nice to 
be able access the 'participants' in the following exceptions:
    NameError (offending name)
    KeyError (collection, offending key)
    IndexError (collection, offending index)

Jeff
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to