[Python-ideas] PEP for executing a module in a package containing relative imports

George Sakkis george.sakkis at gmail.com
Mon Apr 23 00:49:49 CEST 2007

On 4/22/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Steven Bethard wrote:
> > if there's nothing to be passed to the function, why make it a
> > function at all?
> I don't usually like to put big lumps of init code
> at the module level, because it pollutes the module
> namespace with local variables. So I typically end
> up with
>    def main():
>      ...
>      ...
>      ...
>    if __name__ == "__main__":
>      main()
> So I'd be quite happy if I could just define a
> function called __main__() and be done with. I
> don't understand why there's so much opposition
> to that idea.

+1. Although I may start out at the module level, that's typically the
idiom I use eventually for any non-trivial (e.g. more than 1-2 lines)


* Only exception is if the module consists essentially of main(), i.e.
a small standalone script without classes, functions, etc.

More information about the Python-ideas mailing list