Python Poetry: the __main__ Stanza

By Xah Lee. Date:

here's a snippet of Python doc:

This module represents the (otherwise anonymous) scope in which the interpreter's main program executes — commands read either from standard input, from a script file, or from an interactive prompt. It is this environment in which the idiomatic “conditional script” stanza causes a script to run:

if __name__ == "__main__":

from 27.5. __main__ — Top-level script environment — Python v2.7.6 documentation #module-__main__

notice the word “stanza”? Here's a technical writing in a technical manual, and in comes a technical term of poetry. This must be a technical humor.

from the few writings of Guido i've seen, am gussing Guido wrote this piece. His writing's always a bit odd.

also, Python __main__ is a prototypical hack. It came into being because Python's trying to have a consistent namespace scheme: module has namespace, therefore global stuff must belong to some “module” too, thus this pseudo-module __main__ was born.

from which, we begot this common nonplus:

if __name__ == "__main__":
    print "I ran as script!"

Python Documentation Sucks

  1. Python Doc Problem: os.system
  2. Python Doc Problem: os.path.split()
  3. Python Doc Problem: sort()
  4. Python Doc Problem: gzip
  5. Python Documentation Problems
  6. Python Documentation Author Masturbation
  7. How to Improve Python Doc; Notes on Rewriting Python Regex Doc
  8. Why Python's Documentation Sucks
  9. Python Poetry: the __main__ Stanza
  10. perldoc Coming of Age, What Python Can Learn From?
  11. Examples of Quality Documentation in Computing Industry
  12. Python Doc Links Dead
  13. Python Doc Links All Dead
  14. Python = Pretentious Sheet
  15. Optional Function Parameters in Computer Language Docs (the idiocy thereof)

If you have a question, put $5 at patreon and message me.