On Tue, Jun 16, 2009 at 4:54 PM, mrstevegross<mrstevegr...@gmail.com> 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. Maybe there's some special __init__() mechanism for
> modules? Or should I use the 'if __name__ != '__main__'' trick?
>

I think what you are doing is fine. The only thing that I would do
differently is rename 'something' to 'initialize'. That way your
intent is really obvious.


-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to