A little debugging advice (was Re: None)

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Tue Oct 23 17:05:51 EDT 2001


On Tue, 23 Oct 2001 13:01:09 -0500, Larry Whitley <ldw at us.ibm.com> wrote:
>But Python complains that None is a variable that has not been previously
>set.  

It's most likely that you have a typo, like none, Non, N0ne, etc.  

If you have double checked it carefully and still cannot figure out, there
is one trick that almost always works: start a Python interpreter and
copy-paste the variable name (don't type them!), like

>>> None
>>> `None`
'None'

If this still does not solve the problem, post the code and error message
(or lack of error message) here -- by copy-and-pasting instead of
paraphrasing -- the error is likely to be a typo and any retyping is likely
to hide it or obscure it.

In the unlikely event that you see things like

>>> None
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'None' is not defined

and post them here, people would be more intrigged and speculate on the
possibility that you did

>>> del __builtin__.None 

or things like that.

Very often you'll solve the problem while trying to make an example that's
suitable to copy and paste.  That happened to me numerous times.

The take home message is that without copy and paste people would most
likely just assume you made a typo somewhere and leave it to yourself to
find out.

Huaiyu



More information about the Python-list mailing list