This is an artifact of the interactive interpreter,
True. You can avoid the artifact by wrapping the test in a function:
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
... def __repr__ (self):
... return b
...
... try:
... obj
... except NameError:
... return False
... return True
...
... print "`a` is defined"
... else:
... print "`a` is not defined"
...
`a` is defined
... print "`b` is defined"
... else:
... print "`b` is not defined"
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
At the cost of it not quite working when the function is called with an
undefined name. I suppose the print statements could be crafted to make it
look better.
Mel.