if (__name__ == '__main__'): main(sys.argv[1:])

Peter Hansen peter at engcorp.com
Tue Apr 20 18:13:12 EDT 2004


Eli Stevens (WG.c) wrote:

> I have a question about proper Python style when it comes to having a main
> function in a module.  I'm fairly new to Python - a few months of
> very-part-time tinkering (lots'o'Java at work, shrug); my apologies if this
> has been hashed out before.  Random Googling didn't enlighten me, so instead
> I'll ask here.  :)
> 
> if (__name__ == '__main__'):
>   main(sys.argv[1:])
vs.
> if (__name__ == '__main__'):
>   main()

As I think you suspected, "good style" is best determined in this
case by testability.  Go with the former and you aren't likely
to regret it.

-Peter



More information about the Python-list mailing list