about main()

Chris Angelico rosuav at gmail.com
Thu Jul 5 09:20:29 EDT 2018

On Thu, Jul 5, 2018 at 9:20 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Rhodri James <rhodri at kynesim.co.uk>:
>> I'm not a big fan of "main()" functions myself; creating a function
>> which will be called exactly once seems rather wasteful.
> A function is the encapsulation of a distinct ... well ... function.
> Functions that are called just once are desirable.
> So I'm saying the opposite:
>  * Have no code outside functions.

So, no import statements outside functions, no "if name is main"
incantation, and especially, no function definitions outside
functions, because they are themselves code.

What code is permitted outside functions and what isn't?


More information about the Python-list mailing list