[TriLUG] making a python module
Joseph Mack NA3T
jmack at wm7d.net
Tue Feb 12 10:27:14 EST 2008
On Sat, 9 Feb 2008, bcpowell at email.unc.edu wrote:
> The python idiom for this is to condition your execution on the value
> of the __name__ variable. This is set to the module name if the file
> has been imported as a module, and has the special value "__main__" if
> the file is being run as a script by the python interpreter. So you can
> put your test code inside a 'if __name__ == "__main__":' block. For
> instance:
(BTW thanks for this. I didn't find a whole lot on this in
google).
the python 2.5 documentation
(docs.python.org/download.html), section 6.1 "More on
Modules" says that global namespace code is executed on
loading a module, to do any initialisation required for
loading. I've initialised code on running (set vars to 0
say) but never initialised any code on loading.
What might you want to initialise in a python module on
loading (and not running)?
Thanks Joe
--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!
More information about the TriLUG
mailing list