Any other Python flaws?

Steve Holden sholden at holdenweb.com
Mon Jun 18 17:31:24 EDT 2001


"Michael Hudson" <mwh at python.net> wrote in message
news:m3d78161uz.fsf at atrus.jesus.cam.ac.uk...
> D-Man <dsh8290 at rit.edu> writes:
>
> > On Fri, Jun 15, 2001 at 02:18:04PM -0500, Michael Chermside wrote:
> > | Oh well... at least people don't bump into this one much. And if you
> > | accidently clobber it, you can restore things with:
> > |
> > | def __None():
> > |     pass
> > | None = __None()
> >
> > Well, that doesn't work.  One of the key features of 'None' is that
> > there only ever exists a single instance.  This would create a new,
> > unique, instance bound to (a more local) 'None'.
>
> No it wouldn't.  Try it!
>
> I agree that what Michael posted doesn't really do what he wanted; but
> it doesn't do what you said, either.
>
> Cheers,
> M.
>
PythonWin 2.0 (#8, Mar  7 2001, 16:04:37) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (MarkH at ActiveState.com) - see
'Help/About PythonWin' for further copyright information.
>>> del __builtins__.None

[PythonWin goes completely AWOL and must be terminated: even "break into
running code" does nothing. On terminating the main window, PythinWin
displays a dialog box entitiled "Python traceback when executing
ExitInstance handler" in which you see the message "<Error getting
traceback - traceback.print_tb() failed>exceptions.NameError: There is no
variable named 'None'"]

However, in a DOS window:

C:\WINDOWS>python
ActivePython 2.0, build 203 (ActiveState Tool Corp.)
based on Python 2.0 (#8, Mar  7 2001, 16:04:37) [MSC 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license" for more information.
>>> del __builtins__.None
>>> None
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: There is no variable named 'None'
>>> def fn():
...   pass
...
>>> fn()
>>> print repr(fn())
None
>>> None
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: There is no variable named 'None'
>>>


The interpreter is designed to reproduce a vestigial environment even when
crucial builtins like None disappear. This doesn't mean it's a good idea to
disappear them...

Also, you should remember that an assignment to None in the local module
namespace doesn't change the real None, which lives in the __builtins__
namesapce.

regards
 Steve
--
http://www.holdenweb.com/







More information about the Python-list mailing list