meta None?
Martin von Loewis
loewis at informatik.hu-berlin.de
Wed Aug 23 09:32:16 EDT 2000
Tripp Lilley <tripp at perspex.com> writes:
> I'd like to implement a meta-None class... that is, a class that behaves
> like None regardless of what you subject it to:
>
> 1: print metaNone # displays 'None'
> 2: print metaNone( ) # displays 'None'
In addition to the comments that you already got, I'd like to point
out that this does *not* behave like None. Suppose metaNone would
behave like None, then
print metaNone
should give you
TypeError: call of non-function (type None)
That is, None is a value of a type None. The value and the type have
similar names, yet they are different objects:
>>> type(None) is None
0
So if you want to have a class/type like thing called metaNone whose
instances behave like None, I propose
def metaNone():
return None
That gives the desired output on 2 and 4, and reasonable output on 3
(metaNone is None should fail).
Regards,
Martin
More information about the Python-list
mailing list