module not callable - why not?

Hung Jung Lu hungjunglu at yahoo.com
Sun Apr 18 13:56:59 EDT 2004


One more, I promise I'll stop.

(i) For getting attributes by string names, for attributes of
instances you do getattr(self, 'name'), for module attributes you do
globals()['name']. I mention this because every once a month or so a
newbie would ask how to get module level attributes by name.

I'm not saying Python made the mistake alone: everyone else in
C++/Java, etc. made the same mistakes and a lot more. I'm saying that
in hindsight, prototype-based OOP would have saved a lot of troubles.
Why split things into 3 or 4 concepts (instance, class, module,
metaclass, etc.), when you could just have one (object)??? When you
have 3 or 4 different concepts, you are bound to have to duplicate
your effort. That's why people asked for staticmethod/classmethod in
Python (and they were done.) That's why metaclass came to be. That's
why people ask to make modules callable, that's why people ask about
properties for modules. It's tiring and complicated to implement
duplicated features: too much work, too many syntax conflicts. But if
one has started with prototype-based OOP, it only needs to be done
once, instead of 2 or 3 times.

Why do I think it's a good idea to compile a list of these "symptoms"?
Because many people are unfamiliar with prototype-based OOP, and they
think there is nothing (or not much) wrong with class-based OOP like
Python. When they see a list like what I am showing, they will
hopefully understand they have been coping with these
redundancies/inconsistencies for a long long time. Problems that
needed not to be there, in the first place. It's just a way to help
people think "out of the box." :)

regards,

Hung Jung



More information about the Python-list mailing list