diff --git a/Doc/library/__main__.rst b/Doc/library/__main__.rst index 116a9a9d1d..d267d7a47f 100644 --- a/Doc/library/__main__.rst +++ b/Doc/library/__main__.rst @@ -146,7 +146,7 @@ named ``main`` encapsulates the program's primary behavior:: return 0 if __name__ == '__main__': - sys.exit(main()) # next section explains the use of sys.exit + main() Note that if the module didn't encapsulate code inside the ``main`` function but instead put it directly within the ``if __name__ == '__main__'`` block, @@ -188,6 +188,15 @@ your program will have an exit code of ``1``, indicating failure, and the string will be written to :data:`sys.stderr`. The ``echo.py`` example from earlier exemplifies using the ``sys.exit(main())`` convention. +If we wish, we may revise the above example to use this convention:: + + # echo.py with the sys.exit idiom applied + + if __name__ == '__main__': + sys.exit(main()) + + + .. seealso:: `Python Packaging User Guide `_