[Edu-sig] re Python's "batteries included" meme

kirby urner kirby.urner at gmail.com
Fri Feb 4 22:36:07 CET 2011


As I watch students struggle with the:

if __name__ == "__main__":

concept (where to put it, what it does),
it occurs to me we could be doing more
to leverage the already well-worn
"batteries included."

What's different about Python?  The
rich libraries it comes with, including a
cross-platform GUI IDE.  That's one
meaning of "batteries included".

But in another sense we could speak
of the generic module as a "battery" with
the "if run top-level" logic having to do
with battery *testing*.

==== python module ====

[ BATTERIES ]

(functions, classes, global-to-module
names...)

if __name__ == "__main__":

[ BATTERY TESTERS ]

====================

That changes the meaning a little more,
to where each Python module is like
"a battery pack" with its own set of
"testers".

One thing we do with battery packs is
we "import" (promote) their internals
within a top-level namespace that starts
off in some other (alien) module.

Another thing we do with battery packs
is run them top-level namespaces on their
own, perhaps depending on imports
(outsourced resources).

I'm not suggesting harping on this too
much, just another slide that goes by,
but a fun mnemonic, and reinforcing of
an already approved / useful design pattern
(see my previous post in this edu-sig archive
for an example of this self-testing style,
relying on doctest for services).

Kirby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20110204/72512b6d/attachment.html>


More information about the Edu-sig mailing list