Putting the main program in a main function

Nobody nobody at nowhere.invalid
Mon Sep 14 03:25:05 EDT 2015


On Mon, 14 Sep 2015 09:13:47 +0200, ast wrote:

> is it advised to always write programs like that ?

If global (module-scope) variables are initialised by main, then those
variables won't exist unless main() is run, which means that you can't use
it as a module, only as a script.

IMHO, global variables whose initial values can be evaluated without
depending upon or modifying external state should be initialised at the
top level.

If a module has variables which cannot be so initialised, the module needs
to provide an initialisation function which must be called explicitly by
any program or module which imports it.




More information about the Python-list mailing list