Proposed Overhaul of Documentation (Doc/library/__main__.rst)

There have been many complaints about the shortcoming of the documentation
towards informing users about __main__. Both the popular __name__ == '__main__' construct, and the role of in a python module.


I propose a broad overhaul of Doc/library/__main__.rst to address these
shortcomings and to provide a single source of truth on __main__ (in
general!). This is an appropriate place to put this information.
Both the __name__ == '__main__' and fooModule/
constructs reasonably fall under the category of “Python Runtime Services,”
because they both control the way that programs run depending on how they are
used (command-line versus import versus running directly).

The new Doc/library/__main__.rst should have a new synopsis of, “CLIs,
import-time behavior, and if __name__ == ‘__main__’”, reflecting its new and
broader focus.

Additionally, the new docs should have the following distinct sections:

  1. Differentiating between __name__ == ‘__main__’ and
  2. and the -m flag (this is roughly what is there already, although
    it’s not as descriptive as it should be).
  3. __name__ and the if __name__ == '__main__' construct.

If there is interest, I would be happy to open uptake this work on as soon as there is
consensus around this plan. I’m looking forward to hearing what you think!


**correction: the latest bpo on this topic was 39452, not 38452!


I decided to press forward with this via bpo-39452. Please feel free to contribute to the discussion or provide more code review on the GitHub PR (or the bpo)!