Guidance on initialization code in a module

Scott David Daniels Scott.Daniels at Acm.Org
Tue Jun 16 18:05:06 EDT 2009


mrstevegross wrote:
> 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.

Seems fine there.  I'd add a comment like:

     something() #initialize the frambus so the whatzies are set up.

Perhaps I'd choose better names :-)

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list