Code in __init__.py, is it bad form?

Benjamin Peterson benjamin at python.org
Mon Feb 23 21:41:33 EST 2009


Michael Crute <mcrute <at> gmail.com> writes:
> On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden <steve <at> holdenweb.com> wrote:
> > No, it's absolutely fine. One common usage is to import symbols from
> > sub-modules so that they are available from a simple import of the package.
> 
> Yeah, I use it often for that I'm talking more about stuff like
> utility functions, main methods, etc...

There's no overarching Python doctrine forbidding you to do it. It has simply
become a matter of taste. Personally, I tend to put utility functions in their
own module (eg. util), but I do use __init__ for main methods and such.







More information about the Python-list mailing list