Why Python forbids multiple instances of one module?

CHEN Guang dr.cg at 126.com
Wed Jul 7 10:28:56 EDT 2010


>> Why Python forbids multiple instances of one module?
>> If only Python allows multiple instances of one module, module will
>> be enough to replace class in most cases.
>> After all, it is much easier to write a module than a class, at least we do
>> not have to write self everywhere.

> If you really want to do that, it should be possible by deleting the
> entry from sys.modules and re-importing it.  You save yourself having
> to explicitly write self everywhere, but instead you have to declare
> all your "instance" variables as globals in each "method" that uses
> them, which isn't much less of a chore.  You also lose inheritance,
> properties (and descriptors in general), magic method support,
> metaclasses, and pretty much all the other nice features that
> new-style classes have to offer.
 
Wow, it works! Thanks a lot for the good idea. 
It is cool to write, test, debug and maintain POP codes, while realizing the OOP power.
I think inheritance might be simulated with:
from parentModule import *
I really expect for the day when operator overloading and new-style class features find their way into module.
Thans again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100707/71597d89/attachment.html>


More information about the Python-list mailing list