instance as fake module (Re: why is there no class (static) methods in Python ?)

Alex Martelli aleaxit at
Tue Jun 19 17:33:35 EDT 2001

<James_Althoff at> wrote in message
news:mailman.992978370.21848.python-list at
> But more to the point, I think that since in Python "everything is a
> first-class object" -- which is great -- and since classes, therefore, are
> first-class objects it would be nice (and powerful) if you could define
> methods that you could invoke on such class objects.  (And such methods
> should support inheritance and override, of course.)

Dictionaries, lists and functions are also first-class objects, by the
same token.  If what you say IS indeed the rationale for having
'methods that you could invoke' on class-objects, then by exactly
the same rationale there must be the same ability on dictionaries,
lists, and functions, right...?

That "something is a first-class object" doesn't mean you have to
be able to apply *EVERY* operation to it -- you can't "call" a list
nor can you "slice" a function, for example.  Rather, it means that
operations *applicable to objects in general* can also be applied
to that object: passing as function parameter, returning as function
result, more generally binding to any generic kind of reference (item
in a list or tuple, value in a dictionary) -- the ability of being the
_key_ in a dictionary requires hashability (either immutability or
not defining == as different from 'is', in practice:-).  Therefore it
seems that your sillogism is invalid -- "classes are 1st class objs",
"all 1st class objs can have methods defined on them", therefore
"classes must be able to have methods defined on them" -- alas,
or hurrah, the second premise does not hold.


More information about the Python-list mailing list