about main()

Rhodri James rhodri at kynesim.co.uk
Thu Jul 5 06:22:50 EDT 2018


On 05/07/18 09:43, Abdur-Rahmaan Janhangeer wrote:
> just when to use main() in
> 
> if __name__ == '__main__' :
>      main()
> 
> is far is it good in py?
> 
> or should file intended to be run just not include it?

It's a matter of taste.  If your "file intended to be run" also contains 
things that might be useful as a module, use the "if __name__ == 
'__main__'" trick.  Otherwise it can be more of a distraction than a 
help.  I'm not a big fan of "main()" functions myself; creating a 
function which will be called exactly once seems rather wasteful.

-- 
Rhodri James *-* Kynesim Ltd



More information about the Python-list mailing list