Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'broken': 0.03; 'interpreter': 0.04; 'guido': 0.05; 'arguments': 0.07; 'layers': 0.07; 'python': 0.09; 'exist.': 0.09; 'logic': 0.09; 'lookup': 0.09; 'nameerror:': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '*real*': 0.16; 'bugs,': 0.16; 'cc:name:python list': 0.16; 'nameerror': 0.16; 'variables;': 0.16; 'wrote:': 0.17; 'module': 0.19; 'trying': 0.21; 'do.': 0.21; 'trace': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(most': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'occurred': 0.29; "skip:' 10": 0.30; 'e.g.': 0.30; 'function': 0.30; 'error': 0.30; 'helpful': 0.30; 'code': 0.31; 'file': 0.32; 'johnson': 0.32; 'function.': 0.33; 'that!': 0.33; 'traceback': 0.33; 'received:google.com': 0.34; 'sometimes': 0.35; 'useful': 0.36; 'thank': 0.36; 'skip:p 20': 0.36; 'does': 0.37; 'why': 0.37; 'passed': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'shows': 0.38; 'gives': 0.39; 'your': 0.60; 'different': 0.63; 'information': 0.63; 'more': 0.63; 'within': 0.64; 'generated.': 0.65; 'hints': 0.65; 'levels': 0.66; '2013': 0.84; 'detecting': 0.84; 'oscar': 0.84; 'rick': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=eGr4dffqcjj2fk+uX4VkrNa/nMyOnj/R7K5WNa2RZ6o=; b=XMp+qcZPGVtcwzQaQjSmxkFyTw1tN7ICLmbFMY1CjVAz7zNVEFjD7OGjUiPDLCYVNH nhrXNDpNl7qJUpu+K+mUbfraVpTvcr5PnDy3mxVOR3tTRCz0FBA/PfwTAoiLiA1p8RCY MiXz6b3SzFGNCPWOFYI+w58jXJdVgp40T68wnkDyPB/PJ7e3aE+cidsmQj6oiPtIeW4Z WW0UEBvdf4hpRxyJK59bPVtEYZdSyZup6JVeSR+s1HGY1WURFLVXhnR5XiISwQF62qHj RoBGb2PdkwSrKxcK3pKpLV2CMBo3BHIBLe1MVQMgS6c6rt2XQRH8EEZP94vsxSzfTT3W eBqg== X-Received: by 10.52.71.235 with SMTP id y11mr11100649vdu.43.1363468795038; Sat, 16 Mar 2013 14:19:55 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Oscar Benjamin Date: Sat, 16 Mar 2013 21:19:34 +0000 Subject: Re: PyWart: NameError trackbacks are superfluous To: Rick Johnson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363468797 news.xs4all.nl 6841 [2001:888:2000:d::a6]:37682 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41329 On 16 March 2013 18:27, Rick Johnson wrote: > > Sometimes many levels of trace messages can be helpful when detecting bug= s, however, in the case of NameErrors, these "nuggets" ejected from deep w= ithin the bowls of the Python interpreter are nothing more than steaming pi= les of incomprehensible crap! > > We don't need multiple layers of traces for NameErrors. Python does not h= ave *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 contain= s 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 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