PyWart: Python modules are not so "modular" after all!

R

Rick Johnson

============================================================
The Pros of Python Modules:
============================================================

Python modules require no special syntax to create, nor do
they induce extra indentation in your source code to
maintain readability. Simply write some Python code in an
editor, save it with a py|pyw extension, throw in a
directory that python can find, and WHAMO, you've got
yourself an importable module namespace!

Of all the package implementations i've seen, Python's use
of the source file as a module is absolutely my favorite

But don't pucker up your benevolent anus just yet!

============================================================
The Cons of Python Modules:
============================================================

1. Modules cannot be extended or manipulated by the
programmer. Basically the PyGods have handed us modules,
but they failed to give us any tools to manipulate them --
heck, they might as well have blessed us an unlimited
supply of high carbon steel but cursed us with an
atmosphere that does not support combustion.

What good is ANY namespace when you cannot override it's
fundamental interface? And interfaces are the key to OOP!

Is __setattr__/__getattr__ ringing a bell people?
 
R

Rick Johnson

import sys
sys.modules["mymodule"] = any_object_you_like()

Thanks for this great advice!

I'm not particularly fond of injecting names and objects in
this manner due to the "surprise factor", especially when
the names are going to be global, but i'm going to do it
anyway since python gives me no other choice!

*evil-grin*

However, there is no reason why "good" cannot prevail over
"evil". By utilizing an intelligent design, logical
hierarchy, and most importantly: quality documentation and
commenting to shine a light on such dark and mystical
practices, i can elevate a kludge into the realms of
elegance.

Stay tuned for a future thread discussion on the topic...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top