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

James_Althoff at James_Althoff at
Tue Jun 19 21:17:13 CEST 2001

Alex Martelli wrote:
>James_Althoff at> wrote in message
>> How would such an approach work with "import", "from", "__import__",
>Pretty well, thanks (it DOES give problems with 'reload', though,
>if that is what you mean by 'etc':-).  Why not give it a try -- it
>*IS* as simple as a crystal-clear spring, after all.

Well I have to admit, I'm not really sure what it is that makes a
"crystal-clear spring" "simple".  (You are talking about water, right?)  ;

Seriously, I didn't mean to say that using a "substitute module object" was
not a useful concept in general.  I agree that it can be useful.  I meant
that in this particular case using a "substitute module object" to try to
implement "inheritance with override" for module functions didn't seem (to
me) like a good approach for class methods.  OTOH, the idea of using a
substitute module object for enforcing constants (as you posted previously)
or for lazing imports, for example, seem like interesting and useful (and
simple ;-) ) techniques.


>> And use this as the standard idiom for modules?
>I'll pass on this one.  I suspect that by-far-MOST modules have
>no need for __getattr__ and __setattr__, so I don't really see
>why having a module replace its entry in sys.modules would ever
>become "THE standard idiom".  But when I *DO* need a "module
>__getattr__" etc, it seems to work pretty well today.
>I'll pass on metaclasses, "true class methods", etc, too -- it
>does not appear to me that the instance-as-a-fake-module idea
>gives anywhere near ALL the power that such deep concepts might
>yield.  But I haven't done nearly enough Smalltalking to feel
>the need for such specific packaging-of-power deep in my bones.
>Specifically, my personal gut feeling is that classes are nice
>but vastly overrated in most OO literature,

I guess I don't feel the same about this one.  I don't think classes are
vastly overrated.  I just like 'em!  (Although I'll admit that I've seen my
share of badly designed and improperly used ones. :-) ).
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.)



More information about the Python-list mailing list