Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41329
| References | <e6e760f7-eb3a-41c8-b52c-f14ee73aabb1@googlegroups.com> |
|---|---|
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Date | 2013-03-16 21:19 +0000 |
| Subject | Re: PyWart: NameError trackbacks are superfluous |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3372.1363468797.2939.python-list@python.org> (permalink) |
On 16 March 2013 18:27, Rick Johnson <rantingrickjohnson@gmail.com> wrote:
>
> Sometimes many levels of trace messages can be helpful when detecting bugs, however, in the case of NameErrors, these "nuggets" ejected from deep within the bowls of the Python interpreter are nothing more than steaming piles of incomprehensible crap!
>
> We don't need multiple layers of traces for NameErrors. Python does not have *real* global variables; and thank Guido for that! All we need to know is which module the error occurred in AND which line of that module contains the offensive lookup of a name that does not exist.
[SNIP]
NameErrors can occur conditionally depending on e.g. the arguments to
a function. Consider the following script:
# tmp.py
def broken(x):
if x > 2:
print(x)
else:
print(undefined_name)
broken(1)
When run it gives a NameError with a traceback:
$ python tmp.py
Traceback (most recent call last):
File "tmp3.py", line 8, in <module>
broken(1)
File "tmp3.py", line 6, in broken
print(undefined_name)
NameError: global name 'undefined_name' is not defined
The traceback shows the arguments passed to the broken function that
caused the NameError to be generated. Different arguments would not
have generated the NameError. This information can be useful if the
logic of the function in question is complicated. It also hints at why
you were calling the function and what your code is trying to do.
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PyWart: NameError trackbacks are superfluous Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-16 11:27 -0700
Re: PyWart: NameError trackbacks are superfluous Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-03-16 21:19 +0000
Re: PyWart: NameError trackbacks are superfluous Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-16 15:39 -0700
Re: PyWart: NameError trackbacks are superfluous Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-03-16 23:29 +0000
Re: PyWart: NameError trackbacks are superfluous Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-16 16:50 -0700
Re: PyWart: NameError trackbacks are superfluous Chris Angelico <rosuav@gmail.com> - 2013-03-17 11:00 +1100
Re: PyWart: NameError trackbacks are superfluous Tim Chase <python.list@tim.thechases.com> - 2013-03-16 18:36 -0500
Re: PyWart: NameError trackbacks are superfluous Chris Angelico <rosuav@gmail.com> - 2013-03-17 10:48 +1100
Re: PyWart: NameError trackbacks are superfluous Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-16 23:48 +0000
Re: PyWart: NameError trackbacks are superfluous Chris Angelico <rosuav@gmail.com> - 2013-03-17 10:59 +1100
Re: PyWart: NameError trackbacks are superfluous Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-16 17:11 -0700
Re: PyWart: NameError trackbacks are superfluous Michael Torrie <torriem@gmail.com> - 2013-03-16 19:58 -0600
Re: PyWart: NameError trackbacks are superfluous Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-17 03:14 +0000
Re: PyWart: NameError trackbacks are superfluous Chris Angelico <rosuav@gmail.com> - 2013-03-17 14:19 +1100
Re: PyWart: NameError trackbacks are superfluous Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-03-16 21:13 -0700
Re: PyWart: NameError trackbacks are superfluous Jason Swails <jason.swails@gmail.com> - 2013-03-17 17:22 -0400
csiph-web