Guidance on initialization code in a module

mrstevegross mrstevegross at gmail.com
Tue Jun 16 22:54:01 CEST 2009


Is there a common way to initialize various stuff in a module? That
is, I have some code in my module that I want to run whenever the
module is imported. Currently, my module looks like this:

=== foo.py ===
def something():
  ...

def somethingelse():
  ...

something()
=== EOF ===

Is the 'something()' line at the end in an ok location? I just put it
at the end. Maybe there's some special __init__() mechanism for
modules? Or should I use the 'if __name__ != '__main__'' trick?

Thanks,
--Steve



More information about the Python-list mailing list