|
| 1 | +# SOME DESCRIPTIVE TITLE. |
| 2 | +# Copyright (C) 2001-2023, Python Software Foundation |
| 3 | +# This file is distributed under the same license as the Python package. |
| 4 | +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
| 5 | +# |
| 6 | +# Translators: |
| 7 | +# Transifex Bot <>, 2023 |
| 8 | +# |
| 9 | +#, fuzzy |
| 10 | +msgid "" |
| 11 | +msgstr "" |
| 12 | +"Project-Id-Version: Python 3.11\n" |
| 13 | +"Report-Msgid-Bugs-To: \n" |
| 14 | +"POT-Creation-Date: 2023-05-19 14:13+0000\n" |
| 15 | +"PO-Revision-Date: 2021-06-28 00:54+0000\n" |
| 16 | +"Last-Translator: Transifex Bot <>, 2023\n" |
| 17 | +"Language-Team: Polish (https://app.transifex.com/python-doc/teams/5390/pl/)\n" |
| 18 | +"MIME-Version: 1.0\n" |
| 19 | +"Content-Type: text/plain; charset=UTF-8\n" |
| 20 | +"Content-Transfer-Encoding: 8bit\n" |
| 21 | +"Language: pl\n" |
| 22 | +"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : (n%10>=2 && n%10<=4) && " |
| 23 | +"(n%100<12 || n%100>14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && " |
| 24 | +"n%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n" |
| 25 | + |
| 26 | +msgid ":mod:`__main__` --- Top-level code environment" |
| 27 | +msgstr "" |
| 28 | + |
| 29 | +msgid "" |
| 30 | +"In Python, the special name ``__main__`` is used for two important " |
| 31 | +"constructs:" |
| 32 | +msgstr "" |
| 33 | + |
| 34 | +msgid "" |
| 35 | +"the name of the top-level environment of the program, which can be checked " |
| 36 | +"using the ``__name__ == '__main__'`` expression; and" |
| 37 | +msgstr "" |
| 38 | + |
| 39 | +msgid "the ``__main__.py`` file in Python packages." |
| 40 | +msgstr "" |
| 41 | + |
| 42 | +msgid "" |
| 43 | +"Both of these mechanisms are related to Python modules; how users interact " |
| 44 | +"with them and how they interact with each other. They are explained in " |
| 45 | +"detail below. If you're new to Python modules, see the tutorial section :" |
| 46 | +"ref:`tut-modules` for an introduction." |
| 47 | +msgstr "" |
| 48 | + |
| 49 | +msgid "``__name__ == '__main__'``" |
| 50 | +msgstr "" |
| 51 | + |
| 52 | +msgid "" |
| 53 | +"When a Python module or package is imported, ``__name__`` is set to the " |
| 54 | +"module's name. Usually, this is the name of the Python file itself without " |
| 55 | +"the ``.py`` extension::" |
| 56 | +msgstr "" |
| 57 | + |
| 58 | +msgid "" |
| 59 | +"If the file is part of a package, ``__name__`` will also include the parent " |
| 60 | +"package's path::" |
| 61 | +msgstr "" |
| 62 | + |
| 63 | +msgid "" |
| 64 | +"However, if the module is executed in the top-level code environment, its " |
| 65 | +"``__name__`` is set to the string ``'__main__'``." |
| 66 | +msgstr "" |
| 67 | + |
| 68 | +msgid "What is the \"top-level code environment\"?" |
| 69 | +msgstr "" |
| 70 | + |
| 71 | +msgid "" |
| 72 | +"``__main__`` is the name of the environment where top-level code is run. " |
| 73 | +"\"Top-level code\" is the first user-specified Python module that starts " |
| 74 | +"running. It's \"top-level\" because it imports all other modules that the " |
| 75 | +"program needs. Sometimes \"top-level code\" is called an *entry point* to " |
| 76 | +"the application." |
| 77 | +msgstr "" |
| 78 | + |
| 79 | +msgid "The top-level code environment can be:" |
| 80 | +msgstr "" |
| 81 | + |
| 82 | +msgid "the scope of an interactive prompt::" |
| 83 | +msgstr "" |
| 84 | + |
| 85 | +msgid "the Python module passed to the Python interpreter as a file argument:" |
| 86 | +msgstr "" |
| 87 | + |
| 88 | +msgid "" |
| 89 | +"the Python module or package passed to the Python interpreter with the :" |
| 90 | +"option:`-m` argument:" |
| 91 | +msgstr "" |
| 92 | + |
| 93 | +msgid "Python code read by the Python interpreter from standard input:" |
| 94 | +msgstr "" |
| 95 | + |
| 96 | +msgid "" |
| 97 | +"Python code passed to the Python interpreter with the :option:`-c` argument:" |
| 98 | +msgstr "" |
| 99 | + |
| 100 | +msgid "" |
| 101 | +"In each of these situations, the top-level module's ``__name__`` is set to " |
| 102 | +"``'__main__'``." |
| 103 | +msgstr "" |
| 104 | + |
| 105 | +msgid "" |
| 106 | +"As a result, a module can discover whether or not it is running in the top-" |
| 107 | +"level environment by checking its own ``__name__``, which allows a common " |
| 108 | +"idiom for conditionally executing code when the module is not initialized " |
| 109 | +"from an import statement::" |
| 110 | +msgstr "" |
| 111 | + |
| 112 | +msgid "" |
| 113 | +"For a more detailed look at how ``__name__`` is set in all situations, see " |
| 114 | +"the tutorial section :ref:`tut-modules`." |
| 115 | +msgstr "" |
| 116 | + |
| 117 | +msgid "Idiomatic Usage" |
| 118 | +msgstr "" |
| 119 | + |
| 120 | +msgid "" |
| 121 | +"Some modules contain code that is intended for script use only, like parsing " |
| 122 | +"command-line arguments or fetching data from standard input. If a module " |
| 123 | +"like this was imported from a different module, for example to unit test it, " |
| 124 | +"the script code would unintentionally execute as well." |
| 125 | +msgstr "" |
| 126 | + |
| 127 | +msgid "" |
| 128 | +"This is where using the ``if __name__ == '__main__'`` code block comes in " |
| 129 | +"handy. Code within this block won't run unless the module is executed in the " |
| 130 | +"top-level environment." |
| 131 | +msgstr "" |
| 132 | + |
| 133 | +msgid "" |
| 134 | +"Putting as few statements as possible in the block below ``if __name__ == " |
| 135 | +"'__main__'`` can improve code clarity and correctness. Most often, a " |
| 136 | +"function named ``main`` encapsulates the program's primary behavior::" |
| 137 | +msgstr "" |
| 138 | + |
| 139 | +msgid "" |
| 140 | +"Note that if the module didn't encapsulate code inside the ``main`` function " |
| 141 | +"but instead put it directly within the ``if __name__ == '__main__'`` block, " |
| 142 | +"the ``phrase`` variable would be global to the entire module. This is error-" |
| 143 | +"prone as other functions within the module could be unintentionally using " |
| 144 | +"the global variable instead of a local name. A ``main`` function solves " |
| 145 | +"this problem." |
| 146 | +msgstr "" |
| 147 | + |
| 148 | +msgid "" |
| 149 | +"Using a ``main`` function has the added benefit of the ``echo`` function " |
| 150 | +"itself being isolated and importable elsewhere. When ``echo.py`` is " |
| 151 | +"imported, the ``echo`` and ``main`` functions will be defined, but neither " |
| 152 | +"of them will be called, because ``__name__ != '__main__'``." |
| 153 | +msgstr "" |
| 154 | + |
| 155 | +msgid "Packaging Considerations" |
| 156 | +msgstr "" |
| 157 | + |
| 158 | +msgid "" |
| 159 | +"``main`` functions are often used to create command-line tools by specifying " |
| 160 | +"them as entry points for console scripts. When this is done, `pip <https://" |
| 161 | +"pip.pypa.io/>`_ inserts the function call into a template script, where the " |
| 162 | +"return value of ``main`` is passed into :func:`sys.exit`. For example::" |
| 163 | +msgstr "" |
| 164 | + |
| 165 | +msgid "" |
| 166 | +"Since the call to ``main`` is wrapped in :func:`sys.exit`, the expectation " |
| 167 | +"is that your function will return some value acceptable as an input to :func:" |
| 168 | +"`sys.exit`; typically, an integer or ``None`` (which is implicitly returned " |
| 169 | +"if your function does not have a return statement)." |
| 170 | +msgstr "" |
| 171 | + |
| 172 | +msgid "" |
| 173 | +"By proactively following this convention ourselves, our module will have the " |
| 174 | +"same behavior when run directly (i.e. ``python3 echo.py``) as it will have " |
| 175 | +"if we later package it as a console script entry-point in a pip-installable " |
| 176 | +"package." |
| 177 | +msgstr "" |
| 178 | + |
| 179 | +msgid "" |
| 180 | +"In particular, be careful about returning strings from your ``main`` " |
| 181 | +"function. :func:`sys.exit` will interpret a string argument as a failure " |
| 182 | +"message, so your program will have an exit code of ``1``, indicating " |
| 183 | +"failure, and the string will be written to :data:`sys.stderr`. The ``echo." |
| 184 | +"py`` example from earlier exemplifies using the ``sys.exit(main())`` " |
| 185 | +"convention." |
| 186 | +msgstr "" |
| 187 | + |
| 188 | +msgid "" |
| 189 | +"`Python Packaging User Guide <https://packaging.python.org/>`_ contains a " |
| 190 | +"collection of tutorials and references on how to distribute and install " |
| 191 | +"Python packages with modern tools." |
| 192 | +msgstr "" |
| 193 | + |
| 194 | +msgid "``__main__.py`` in Python Packages" |
| 195 | +msgstr "" |
| 196 | + |
| 197 | +msgid "" |
| 198 | +"If you are not familiar with Python packages, see section :ref:`tut-" |
| 199 | +"packages` of the tutorial. Most commonly, the ``__main__.py`` file is used " |
| 200 | +"to provide a command-line interface for a package. Consider the following " |
| 201 | +"hypothetical package, \"bandclass\":" |
| 202 | +msgstr "" |
| 203 | + |
| 204 | +msgid "" |
| 205 | +"``__main__.py`` will be executed when the package itself is invoked directly " |
| 206 | +"from the command line using the :option:`-m` flag. For example:" |
| 207 | +msgstr "" |
| 208 | + |
| 209 | +msgid "" |
| 210 | +"This command will cause ``__main__.py`` to run. How you utilize this " |
| 211 | +"mechanism will depend on the nature of the package you are writing, but in " |
| 212 | +"this hypothetical case, it might make sense to allow the teacher to search " |
| 213 | +"for students::" |
| 214 | +msgstr "" |
| 215 | + |
| 216 | +msgid "" |
| 217 | +"Note that ``from .student import search_students`` is an example of a " |
| 218 | +"relative import. This import style can be used when referencing modules " |
| 219 | +"within a package. For more details, see :ref:`intra-package-references` in " |
| 220 | +"the :ref:`tut-modules` section of the tutorial." |
| 221 | +msgstr "" |
| 222 | + |
| 223 | +msgid "" |
| 224 | +"The contents of ``__main__.py`` typically isn't fenced with ``if __name__ == " |
| 225 | +"'__main__'`` blocks. Instead, those files are kept short, functions to " |
| 226 | +"execute from other modules. Those other modules can then be easily unit-" |
| 227 | +"tested and are properly reusable." |
| 228 | +msgstr "" |
| 229 | + |
| 230 | +msgid "" |
| 231 | +"If used, an ``if __name__ == '__main__'`` block will still work as expected " |
| 232 | +"for a ``__main__.py`` file within a package, because its ``__name__`` " |
| 233 | +"attribute will include the package's path if imported::" |
| 234 | +msgstr "" |
| 235 | + |
| 236 | +msgid "" |
| 237 | +"This won't work for ``__main__.py`` files in the root directory of a .zip " |
| 238 | +"file though. Hence, for consistency, minimal ``__main__.py`` like the :mod:" |
| 239 | +"`venv` one mentioned below are preferred." |
| 240 | +msgstr "" |
| 241 | + |
| 242 | +msgid "" |
| 243 | +"See :mod:`venv` for an example of a package with a minimal ``__main__.py`` " |
| 244 | +"in the standard library. It doesn't contain a ``if __name__ == '__main__'`` " |
| 245 | +"block. You can invoke it with ``python -m venv [directory]``." |
| 246 | +msgstr "" |
| 247 | + |
| 248 | +msgid "" |
| 249 | +"See :mod:`runpy` for more details on the :option:`-m` flag to the " |
| 250 | +"interpreter executable." |
| 251 | +msgstr "" |
| 252 | + |
| 253 | +msgid "" |
| 254 | +"See :mod:`zipapp` for how to run applications packaged as *.zip* files. In " |
| 255 | +"this case Python looks for a ``__main__.py`` file in the root directory of " |
| 256 | +"the archive." |
| 257 | +msgstr "" |
| 258 | + |
| 259 | +msgid "``import __main__``" |
| 260 | +msgstr "" |
| 261 | + |
| 262 | +msgid "" |
| 263 | +"Regardless of which module a Python program was started with, other modules " |
| 264 | +"running within that same program can import the top-level environment's " |
| 265 | +"scope (:term:`namespace`) by importing the ``__main__`` module. This " |
| 266 | +"doesn't import a ``__main__.py`` file but rather whichever module that " |
| 267 | +"received the special name ``'__main__'``." |
| 268 | +msgstr "" |
| 269 | + |
| 270 | +msgid "Here is an example module that consumes the ``__main__`` namespace::" |
| 271 | +msgstr "" |
| 272 | + |
| 273 | +msgid "Example usage of this module could be as follows::" |
| 274 | +msgstr "" |
| 275 | + |
| 276 | +msgid "Now, if we started our program, the result would look like this:" |
| 277 | +msgstr "" |
| 278 | + |
| 279 | +msgid "" |
| 280 | +"The exit code of the program would be 1, indicating an error. Uncommenting " |
| 281 | +"the line with ``my_name = \"Dinsdale\"`` fixes the program and now it exits " |
| 282 | +"with status code 0, indicating success:" |
| 283 | +msgstr "" |
| 284 | + |
| 285 | +msgid "" |
| 286 | +"Note that importing ``__main__`` doesn't cause any issues with " |
| 287 | +"unintentionally running top-level code meant for script use which is put in " |
| 288 | +"the ``if __name__ == \"__main__\"`` block of the ``start`` module. Why does " |
| 289 | +"this work?" |
| 290 | +msgstr "" |
| 291 | + |
| 292 | +msgid "" |
| 293 | +"Python inserts an empty ``__main__`` module in :attr:`sys.modules` at " |
| 294 | +"interpreter startup, and populates it by running top-level code. In our " |
| 295 | +"example this is the ``start`` module which runs line by line and imports " |
| 296 | +"``namely``. In turn, ``namely`` imports ``__main__`` (which is really " |
| 297 | +"``start``). That's an import cycle! Fortunately, since the partially " |
| 298 | +"populated ``__main__`` module is present in :attr:`sys.modules`, Python " |
| 299 | +"passes that to ``namely``. See :ref:`Special considerations for __main__ " |
| 300 | +"<import-dunder-main>` in the import system's reference for details on how " |
| 301 | +"this works." |
| 302 | +msgstr "" |
| 303 | + |
| 304 | +msgid "" |
| 305 | +"The Python REPL is another example of a \"top-level environment\", so " |
| 306 | +"anything defined in the REPL becomes part of the ``__main__`` scope::" |
| 307 | +msgstr "" |
| 308 | + |
| 309 | +msgid "" |
| 310 | +"Note that in this case the ``__main__`` scope doesn't contain a ``__file__`` " |
| 311 | +"attribute as it's interactive." |
| 312 | +msgstr "" |
| 313 | + |
| 314 | +msgid "" |
| 315 | +"The ``__main__`` scope is used in the implementation of :mod:`pdb` and :mod:" |
| 316 | +"`rlcompleter`." |
| 317 | +msgstr "" |
0 commit comments