Python "header" files

David Bolen db3l at fitlinxx.com
Wed Jun 9 18:51:39 CEST 2004


beliavsky at aol.com writes:

> For the main programs it actually runs the Python code and does
> calculations before producing HTML. (Pychecker seems to work the same
> way). The "DATA" section contains not only the parameters I set but
> the computed results, which can change every time the program is run,
> especially for simulations. PyDoc does not seem too helpful to me for
> documenting the main program.

It sounds like you haven't protected your main script against being
imported as a module.  It's not so much that pydoc/Pychecker are
"running" your Python code, but that they are importing the modules to
get at the information.  While it's possible to write such a tool that
would instead compile the module and then analyse the resultant
compiled form, it's much easier to just introspect the normal Python
objects as a result of an import, so you'll find that most
introspection tools use the import-and-process approach.  It does have
the side-effect of performing the import (so if modules do
calculations or operations when imported, that get's triggered).

If you haven't already, protect any top-level code in your main
modules inside an:

    if __name__ == "__main__":

block, and you won't find your code running when the module is
processed by tools such as these.  

-- David



More information about the Python-list mailing list