type lookuperror

Chris Angelico rosuav at gmail.com
Thu Aug 18 07:28:06 EDT 2016


On Thu, Aug 18, 2016 at 7:55 PM, meInvent bbird <jobmattcon at gmail.com> wrote:
> actually i would like to remove try except code in all function
>
> and i feel that try except code for a large block code can not
> show which function name , which line number error,
> if use try except for specified code block to show where it has error
> it will have many ugly try except code and need many human force
> to craft the code, i hope that code write once for program to program itself
> in future.
>
> actually this method i ask is not good enough since it will need
> to add many function wrapper.

You can't get a program to program itself. That's called the
Singularity [1], and depending on your point of view, it's either
still in the future, or fundamentally impossible. In any case,
computers today cannot program themselves.

So what exactly is it you're wanting? When an exception happens, the
entire traceback is recorded, and unless you're throwing that away,
it'll be shown to you. Just let the exception bubble all the way up to
top level, and then read the traceback. Some IDEs can even help you
step through the code to see context for each line of traceback;
ipython is also pretty helpful with reading tracebacks. I advise
getting to know the tools you have available, rather than trying to
reinvent the wheel.

ChrisA

[1] https://en.wikipedia.org/wiki/Technological_singularity



More information about the Python-list mailing list