[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

WedWonder: Scripts and Modules

DL Neil <PythonList at DancesWithMice.info> writes:

> ... However, reversing the question in my mind led me to ask (myself):
> how many scripts do I have (in "production use") which are ever used
> (also) as a module by some other script? I think the answer is/was:
> "none"! Accordingly, (spoiler alert: this statement may be heresy) I
> stopped using the "if".

I found that the problem with doing this is that `pydoc' now _runs_ my
scripts, when all I wanted was a quick look at the constants and procedures
defined in them.

It's pretty handy sometimes to fire up `pydoc' in http server mode in a
directory full of random Python code (some scripts and some modules), and
use it to browse around to figure out what everything does.  Scripts that
aren't protected with the usual `if __name__' are more likely to crash
in that situation, often crashing `pydoc' in the process.

In fact, I have been known to add `if __name__' to my colleagues' Python
scripts, just so that I can safely `pydoc' them.

Alan Bawden