From 89b4ba9df84e6b2477adf4d4e7845128ec782ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Ogam?= Date: Sun, 30 Jun 2019 18:52:56 +0200 Subject: [PATCH 1/5] Update __main__.rst --- Doc/library/__main__.rst | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Doc/library/__main__.rst b/Doc/library/__main__.rst index a64faf1bbe3c84..727626d0af0d29 100644 --- a/Doc/library/__main__.rst +++ b/Doc/library/__main__.rst @@ -1,25 +1,24 @@ - -:mod:`__main__` --- Top-level script environment -================================================ +:mod:`__main__` --- Top-level code environment +============================================== .. module:: __main__ - :synopsis: The environment where the top-level script is run. + :synopsis: The environment where top-level code is run. -------------- -``'__main__'`` is the name of the scope in which top-level code executes. -A module's __name__ is set equal to ``'__main__'`` when read from -standard input, a script, or from an interactive prompt. +``'__main__'`` is the name of the environment where top-level code is run. A +module's ``__name__`` is set equal to ``'__main__'`` when the module is run +from the file system, from standard input or from the module namespace (with +the :option:`-m` command line switch), but not when it is imported. -A module can discover whether or not it is running in the main scope by +A module can discover whether or not it is running in the main environment by checking its own ``__name__``, which allows a common idiom for conditionally -executing code in a module when it is run as a script or with ``python --m`` but not when it is imported:: +executing code in a module when it is not imported:: + # Execute only if the module is not imported. if __name__ == "__main__": - # execute only if run as a script main() -For a package, the same effect can be achieved by including a -``__main__.py`` module, the contents of which will be executed when the -module is run with ``-m``. +For a package, the same effect can be achieved by including a __main__.py +module, the contents of which will be executed when the package is run from the +file system or from the module namespace, but not when it is imported. From 530cd4108d27033290b0877507736ca5b5da1709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Ogam?= Date: Sun, 30 Jun 2019 19:22:45 +0200 Subject: [PATCH 2/5] Update __main__.rst --- Doc/library/__main__.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/__main__.rst b/Doc/library/__main__.rst index 727626d0af0d29..e1632e9e5f30cb 100644 --- a/Doc/library/__main__.rst +++ b/Doc/library/__main__.rst @@ -9,7 +9,8 @@ ``'__main__'`` is the name of the environment where top-level code is run. A module's ``__name__`` is set equal to ``'__main__'`` when the module is run from the file system, from standard input or from the module namespace (with -the :option:`-m` command line switch), but not when it is imported. +the :option:`-m` command line switch or the :func:`runpy.run_module` function), +but not when it is imported. A module can discover whether or not it is running in the main environment by checking its own ``__name__``, which allows a common idiom for conditionally From ac8e74c06630b6928d688a787820fef7cdcec728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Ogam?= Date: Wed, 16 Sep 2020 22:46:29 +0200 Subject: [PATCH 3/5] =?UTF-8?q?Take=20Steven=20d=E2=80=99Aprano=E2=80=99s?= =?UTF-8?q?=20review=20into=20account?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Doc/library/__main__.rst | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Doc/library/__main__.rst b/Doc/library/__main__.rst index e1632e9e5f30cb..118b89acf89d03 100644 --- a/Doc/library/__main__.rst +++ b/Doc/library/__main__.rst @@ -7,19 +7,20 @@ -------------- ``'__main__'`` is the name of the environment where top-level code is run. A -module's ``__name__`` is set equal to ``'__main__'`` when the module is run -from the file system, from standard input or from the module namespace (with -the :option:`-m` command line switch or the :func:`runpy.run_module` function), -but not when it is imported. +module's ``__name__`` is set equal to ``'__main__'`` when the module is +initialized from an interactive prompt, from standard input, from a file +argument, from a :option:`-c` argument or from a :option:`-m` argument, but +not when it is initialized from an import statement. A module can discover whether or not it is running in the main environment by checking its own ``__name__``, which allows a common idiom for conditionally -executing code in a module when it is not imported:: +executing code when the module is not initialized from an import statement:: - # Execute only if the module is not imported. - if __name__ == "__main__": - main() + if __name__ == '__main__': + # Execute when the module is not initialized from an import statement. + main() For a package, the same effect can be achieved by including a __main__.py -module, the contents of which will be executed when the package is run from the -file system or from the module namespace, but not when it is imported. +module, the contents of which will be executed when the package is initialized +from a file argument or from a :option:`-m` argument, but not when it is +initialized from an import statement. From d7502444ec3b245b0178aa28393bb3d4f23fb7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Ogam?= Date: Wed, 16 Sep 2020 22:47:55 +0200 Subject: [PATCH 4/5] Rewrap lines --- Doc/library/__main__.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/__main__.rst b/Doc/library/__main__.rst index 118b89acf89d03..76e72a75db6d0c 100644 --- a/Doc/library/__main__.rst +++ b/Doc/library/__main__.rst @@ -6,21 +6,21 @@ -------------- -``'__main__'`` is the name of the environment where top-level code is run. A -module's ``__name__`` is set equal to ``'__main__'`` when the module is -initialized from an interactive prompt, from standard input, from a file -argument, from a :option:`-c` argument or from a :option:`-m` argument, but -not when it is initialized from an import statement. +``'__main__'`` is the name of the environment where top-level code is run. A +module's ``__name__`` is set equal to ``'__main__'`` when the module is +initialized from an interactive prompt, from standard input, from a file +argument, from a :option:`-c` argument or from a :option:`-m` argument, but not +when it is initialized from an import statement. -A module can discover whether or not it is running in the main environment by -checking its own ``__name__``, which allows a common idiom for conditionally +A module can discover whether or not it is running in the main environment by +checking its own ``__name__``, which allows a common idiom for conditionally executing code when the module is not initialized from an import statement:: if __name__ == '__main__': # Execute when the module is not initialized from an import statement. main() -For a package, the same effect can be achieved by including a __main__.py -module, the contents of which will be executed when the package is initialized -from a file argument or from a :option:`-m` argument, but not when it is +For a package, the same effect can be achieved by including a __main__.py +module, the contents of which will be executed when the package is initialized +from a file argument or from a :option:`-m` argument, but not when it is initialized from an import statement. From 5cda36cbd267920ce0ec70cced999f2ae02b1390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Ogam?= Date: Thu, 17 Sep 2020 07:28:30 +0200 Subject: [PATCH 5/5] Remove trailing whitespaces --- Doc/library/__main__.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/library/__main__.rst b/Doc/library/__main__.rst index 76e72a75db6d0c..cb7233b6116b0e 100644 --- a/Doc/library/__main__.rst +++ b/Doc/library/__main__.rst @@ -6,21 +6,21 @@ -------------- -``'__main__'`` is the name of the environment where top-level code is run. A -module's ``__name__`` is set equal to ``'__main__'`` when the module is -initialized from an interactive prompt, from standard input, from a file -argument, from a :option:`-c` argument or from a :option:`-m` argument, but not +``'__main__'`` is the name of the environment where top-level code is run. A +module's ``__name__`` is set equal to ``'__main__'`` when the module is +initialized from an interactive prompt, from standard input, from a file +argument, from a :option:`-c` argument or from a :option:`-m` argument, but not when it is initialized from an import statement. -A module can discover whether or not it is running in the main environment by -checking its own ``__name__``, which allows a common idiom for conditionally +A module can discover whether or not it is running in the main environment by +checking its own ``__name__``, which allows a common idiom for conditionally executing code when the module is not initialized from an import statement:: if __name__ == '__main__': # Execute when the module is not initialized from an import statement. main() -For a package, the same effect can be achieved by including a __main__.py -module, the contents of which will be executed when the package is initialized -from a file argument or from a :option:`-m` argument, but not when it is +For a package, the same effect can be achieved by including a __main__.py +module, the contents of which will be executed when the package is initialized +from a file argument or from a :option:`-m` argument, but not when it is initialized from an import statement. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy