Perl is worse!

Jeffrey C. Ollie jeff at ollie.clive.ia.us
Sat Jul 29 00:45:14 EDT 2000


On Sat, 29 Jul 2000 03:43:38 GMT, Ben Wolfson <rumjuggler at cryptarchy.org> wrote:
>>>> def getnone():
>	pass
>
>>>> import __builtin__
>>>> __builtin__.None = 1
>>>> type(getnone())
><type 'None'>


I think that you are not fully comprehending the difference in Python
between variables and objects.  Variables in Python are nothing more
that references to objects. When you type 'None' in a program, Python
uses the object (usually, the 'None' object) referenced by the label
'None'. As you have found out, you can change which object that the
label 'None' references.

However, when a Python function exits without executing an explicit
'return' statement, the interpreter supplies the real 'None' object,
and not the object referenced by the label 'None'. I'm sure that this
was done (perhaps unintentionally) as a performance enhancement, as
you wouldn't want to incur the expense of a variable dereference every
time a function exited without executing a 'return' statement.

Consider the following code:

>>> a = None
>>> type(a)
<type 'None'>
>>> None = 1
>>> type(None)
<type 'int'>
>>> type(a)
<type 'None'>




More information about the Python-list mailing list