# Copyright (C) 2001-2020, Python Software Foundation # This file is distributed under the same license as the Python package. # Maintained by the python-doc-es workteam. # docs-es@python.org / # https://mail.python.org/mailman3/lists/docs-es.python.org/ # Check https://github.com/python/python-docs-es/blob/3.8/TRANSLATORS to get # the list of volunteers # msgid "" msgstr "" "Project-Id-Version: Python 3.8\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-10-12 19:43+0200\n" "PO-Revision-Date: 2021-10-28 21:47+0200\n" "Last-Translator: Juan C. Tello \n" "Language: es\n" "Language-Team: python-doc-es\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.13.0\n" #: ../Doc/library/__main__.rst:2 msgid ":mod:`__main__` --- Top-level code environment" msgstr ":mod:`__main__` --- Entorno de código de nivel máximo" #: ../Doc/library/__main__.rst:10 msgid "" "In Python, the special name ``__main__`` is used for two important " "constructs:" msgstr "" "En Python, el nombre especial ``__main__`` es utilizado para dos constructos " "importantes:" #: ../Doc/library/__main__.rst:12 msgid "" "the name of the top-level environment of the program, which can be checked " "using the ``__name__ == '__main__'`` expression; and" msgstr "" "el nombre del entorno de máximo nivel del programa, que puede ser verificado " "usando la expresión ``__name__=='__main__'``; y" #: ../Doc/library/__main__.rst:14 msgid "the ``__main__.py`` file in Python packages." msgstr "el archivo ``__main__.py`` en paquetes de Python." #: ../Doc/library/__main__.rst:16 msgid "" "Both of these mechanisms are related to Python modules; how users interact " "with them and how they interact with each other. They are explained in " "detail below. If you're new to Python modules, see the tutorial section :" "ref:`tut-modules` for an introduction." msgstr "" "Ambos de estos mecanismos están relacionados con módulos de Python; como los " "usuarios interactúan con ellos y como ellos interactúan entre sí. Están " "explicados en detalle más abajo. Si estás empezando con los módulos de " "Python, mira la sección tutorial :ref:`tut-modules` para una introducción." #: ../Doc/library/__main__.rst:25 msgid "``__name__ == '__main__'``" msgstr "``__name__ == '__main__'``" #: ../Doc/library/__main__.rst:27 msgid "" "When a Python module or package is imported, ``__name__`` is set to the " "module's name. Usually, this is the name of the Python file itself without " "the ``.py`` extension::" msgstr "" "Cuando un módulo o paquete de Python es importado, ``__name__`` es asignado " "al nombre del módulo. Normalmente, este es el nombre del archivo de Python " "sin la extensión ``.py``::" #: ../Doc/library/__main__.rst:35 msgid "" "If the file is part of a package, ``__name__`` will also include the parent " "package's path::" msgstr "" "Si el archivo es parte de un paquete, ``__name__`` también incluirá la ruta " "del paquete padre::" #: ../Doc/library/__main__.rst:42 msgid "" "However, if the module is executed in the top-level code environment, its " "``__name__`` is set to the string ``'__main__'``." msgstr "" "Sin embargo, si el módulo es ejecutado en el entorno de código de máximo " "nivel, su ``__name__`` se le asigna el valor del string ``'__main__'``." #: ../Doc/library/__main__.rst:46 msgid "What is the \"top-level code environment\"?" msgstr "¿Qué es el \"entorno de código de máximo nivel\"?" #: ../Doc/library/__main__.rst:48 msgid "" "``__main__`` is the name of the environment where top-level code is run. " "\"Top-level code\" is the first user-specified Python module that starts " "running. It's \"top-level\" because it imports all other modules that the " "program needs. Sometimes \"top-level code\" is called an *entry point* to " "the application." msgstr "" "``__main__`` es el nombre del entorno en el cual se ejecuta el código de " "máximo nivel. \"Código de máximo nivel\" es el primer módulo de Python " "especificado por el usuario que empieza a ejecutarse. Es \"de máximo nivel\" " "porque importa todos los demás módulos que necesita el programa. A veces " "\"código de máximo nivel\" es llamado un *punto de entrada* a la aplicación." #: ../Doc/library/__main__.rst:53 msgid "The top-level code environment can be:" msgstr "El entorno de código de máximo nivel puede ser:" #: ../Doc/library/__main__.rst:55 msgid "the scope of an interactive prompt::" msgstr "el ámbito de un intérprete interactivo::" #: ../Doc/library/__main__.rst:60 msgid "the Python module passed to the Python interpreter as a file argument:" msgstr "" "el módulo de Python pasado al intérprete de Python como un argumento de " "archivo:" #: ../Doc/library/__main__.rst:67 msgid "" "the Python module or package passed to the Python interpreter with the :" "option:`-m` argument:" msgstr "" "el módulo o paquete de Python pasado al interprete de Python con el " "argumento :option:`-m`:" #: ../Doc/library/__main__.rst:75 msgid "Python code read by the Python interpreter from standard input:" msgstr "Código de Python leído por el interprete desde input estándar:" #: ../Doc/library/__main__.rst:86 msgid "" "Python code passed to the Python interpreter with the :option:`-c` argument:" msgstr "" "Código de Python pasado al intérprete Python con el argumento :option:`-c`:" #: ../Doc/library/__main__.rst:97 msgid "" "In each of these situations, the top-level module's ``__name__`` is set to " "``'__main__'``." msgstr "" "En cada una de estas situaciones, al ``__name__`` del módulo de máximo nivel " "se le asigna el valor ``'__main__'``." #: ../Doc/library/__main__.rst:100 msgid "" "As a result, a module can discover whether or not it is running in the top-" "level 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::" msgstr "" "En consecuencia, un módulo puede descubrir si se está ejecutando o no en el " "ámbito principal al verificar su propio ``__name__``, lo cual permite un " "vocablo común para ejecutar código condicionalmente cuando el módulo no es " "inicializado desde una declaración de importado::" #: ../Doc/library/__main__.rst:111 msgid "" "For a more detailed look at how ``__name__`` is set in all situations, see " "the tutorial section :ref:`tut-modules`." msgstr "" "Para una vista más detallada de como ``__name__`` es asignado en todas las " "situaciones, ver la sección tutorial :ref:`tut-modules`." #: ../Doc/library/__main__.rst:116 ../Doc/library/__main__.rst:239 msgid "Idiomatic Usage" msgstr "Uso idiomático" #: ../Doc/library/__main__.rst:118 #, fuzzy msgid "" "Some modules contain code that is intended for script use only, like parsing " "command-line arguments or fetching data from standard input. If a module " "like this was imported from a different module, for example to unit test it, " "the script code would unintentionally execute as well." msgstr "" "Algunos módulos contienen código que está pensado para uso de script " "solamente, como para interpretar argumentos de línea de comando u obtener " "datos de la entrada estándar. Cuando un módulo como este fuese importado " "desde un módulo distinto, por ejemplo para realizar una prueba unitaria, el " "código del script se ejecutaría involuntariamente." #: ../Doc/library/__main__.rst:123 msgid "" "This is where using the ``if __name__ == '__main__'`` code block comes in " "handy. Code within this block won't run unless the module is executed in the " "top-level environment." msgstr "" "Aquí es donde es útil usar el código de bloque ``if __name__=='__main__'``. " "El código dentro desde bloque no se ejecutará a menos que el módulo se " "ejecute en el entorno de máximo nivel." #: ../Doc/library/__main__.rst:127 #, fuzzy msgid "" "Putting as few statements as possible in the block below ``if __name__ == " "'__main__'`` can improve code clarity and correctness. Most often, a " "function named ``main`` encapsulates the program's primary behavior::" msgstr "" "Poner cuantas menos declaraciones posible en el bloque debajo de ``if " "__name__=='__main__'`` puede mejorar la claridad y validez del código. Mas a " "menudo, la función llamada ``main`` encapsula el comportamiento principal " "del programa::" #: ../Doc/library/__main__.rst:151 msgid "" "Note that if the module didn't encapsulate code inside the ``main`` function " "but instead put it directly within the ``if __name__ == '__main__'`` block, " "the ``phrase`` variable would be global to the entire module. This is error-" "prone as other functions within the module could be unintentionally using " "the global variable instead of a local name. A ``main`` function solves " "this problem." msgstr "" "Note que si el módulo no encapsulase el código dentro de la función ``main`` " "pero en vez lo pusiese directo dentro del bloque ``if " "__name__=='__main__'``, la variable ``phrase`` sería global al módulo " "entero. Esto está propenso a generar errores ya que otras funciones dentro " "del módulo pudiesen estar usando involuntariamente la variable global en " "lugar de un nombre local. Una función ``main`` resuelve este problema." #: ../Doc/library/__main__.rst:158 msgid "" "Using a ``main`` function has the added benefit of the ``echo`` function " "itself being isolated and importable elsewhere. When ``echo.py`` is " "imported, the ``echo`` and ``main`` functions will be defined, but neither " "of them will be called, because ``__name__ != '__main__'``." msgstr "" "Usar una función ``main`` tiene el beneficio añadido de que la función " "``echo`` está aislada y es importable en otros sitios. Cuando ``echo.py`` es " "importado, las funciones ``echo`` y ``main`` serán definidas, pero ninguna " "de ellas será llamada porque ``__name!='__main__'``." #: ../Doc/library/__main__.rst:165 msgid "Packaging Considerations" msgstr "Consideraciones de empaquetado" #: ../Doc/library/__main__.rst:167 msgid "" "``main`` functions are often used to create command-line tools by specifying " "them as entry points for console scripts. When this is done, `pip `_ inserts the function call into a template script, where the " "return value of ``main`` is passed into :func:`sys.exit`. For example::" msgstr "" "Las funciones ``main`` se utilizan a menudo para crear líneas de comando al " "especificarlas como puntos de entrada para scripts de terminal. Cuando esto " "se hace, `pip `_ inserta la llamada de la función a un " "script plantilla, donde el valor retornado de ``main`` se pasa a :func:`sys." "exit`. Por ejemplo::" #: ../Doc/library/__main__.rst:175 msgid "" "Since the call to ``main`` is wrapped in :func:`sys.exit`, the expectation " "is that your function will return some value acceptable as an input to :func:" "`sys.exit`; typically, an integer or ``None`` (which is implicitly returned " "if your function does not have a return statement)." msgstr "" "Dado que la llamada a ``main`` está dentro de :func:`sys.exit`, la " "expectativa es que tu función devolverá un valor aceptable como una entrada " "a :func:`sys.exit`; típicamente, un int o ``None`` (que se retorna " "implícitamente si tu función no tiene una declaración de retorno)." #: ../Doc/library/__main__.rst:180 #, fuzzy msgid "" "By proactively following this convention ourselves, our module will have the " "same behavior when run directly (i.e. ``python echo.py``) as it will have if " "we later package it as a console script entry-point in a pip-installable " "package." msgstr "" "Al seguir pro-activamente esta convención nosotros mismo, nuestro módulo " "tendrá el mismo comportamiento cuando se ejecuta directamente (es decir, " "``python3 echo.py``) que si luego lo empaquetamos como un punto de entrada " "de script de terminal en un paquete instalable mediante pip." #: ../Doc/library/__main__.rst:185 msgid "" "In particular, be careful about returning strings from your ``main`` " "function. :func:`sys.exit` will interpret a string argument as a failure " "message, so 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." msgstr "" "En particular, ten cuidado al devolver cadenas de texto con tu función " "``main``. :func:`sys.exit` interpretará un argumento de cadena de texto como " "un mensaje de fallo, entonces tu programa tendrá un código de salida de " "``1``, indicando fallo, y la cadena de texto será escrita a :data:`sys." "stderr`. El ejemplo ``echo.py`` de antes muestra como usar la convención " "``sys.exit(main())``." #: ../Doc/library/__main__.rst:193 msgid "" "`Python Packaging User Guide `_ contains a " "collection of tutorials and references on how to distribute and install " "Python packages with modern tools." msgstr "" "`Python Packaging User Guide `_ contiene una " "colección de tutoriales y referencias sobre como distribuir e instalar " "paquetes de Python con herramientas modernas." #: ../Doc/library/__main__.rst:199 msgid "``__main__.py`` in Python Packages" msgstr "``__main__.py`` en paquetes de Python" #: ../Doc/library/__main__.rst:201 msgid "" "If you are not familiar with Python packages, see section :ref:`tut-" "packages` of the tutorial. Most commonly, the ``__main__.py`` file is used " "to provide a command-line interface for a package. Consider the following " "hypothetical package, \"bandclass\":" msgstr "" "Si no estás familiarizado con paquetes de Python, ver la sección :ref:`tut-" "packages` del tutorial. Comúnmente, el archivo ``__main__.py`` es utilizado " "para proveer una interfaz de línea de comando para un paquete. Considera el " "siguiente paquete hipotético, \"*bandclass*\":" #: ../Doc/library/__main__.rst:213 msgid "" "``__main__.py`` will be executed when the package itself is invoked directly " "from the command line using the :option:`-m` flag. For example:" msgstr "" "``__main__.py`` será ejecutado cuando el paquete sea invocado directamente " "desde la línea de comandos usando el indicador :option:`-m`. Por ejemplo:" #: ../Doc/library/__main__.rst:220 msgid "" "This command will cause ``__main__.py`` to run. How you utilize this " "mechanism will depend on the nature of the package you are writing, but in " "this hypothetical case, it might make sense to allow the teacher to search " "for students::" msgstr "" "Este comando causará que ``__main__.py`` se ejecute. El como se use este " "mecanismo dependerá de la naturaleza del paquete que estás escribiendo, pero " "en este caso hipotético, puede tener sentido permitir que el profesor busque " "estudiantes::" #: ../Doc/library/__main__.rst:233 #, fuzzy msgid "" "Note that ``from .student import search_students`` is an example of a " "relative import. This import style can be used when referencing modules " "within a package. For more details, see :ref:`intra-package-references` in " "the :ref:`tut-modules` section of the tutorial." msgstr "" "Note que ``from .student import search_students`` es un ejemplo de una " "importación relativa. Este estilo de importación debe ser utilizado cuando " "se hace referencia a módulos dentro de un paquete. Para más detalles, ver :" "ref:`intra-package-references` en la sección :ref:`tut-modules` del tutorial." #: ../Doc/library/__main__.rst:241 #, fuzzy msgid "" "The content of ``__main__.py`` typically isn't fenced with an ``if __name__ " "== '__main__'`` block. Instead, those files are kept short and import " "functions to execute from other modules. Those other modules can then be " "easily unit-tested and are properly reusable." msgstr "" "Los contenidos de ``__main__.py`` no están típicamente acotados dentro de " "bloques ``if __name__=='__main__'``. En cambio, esos archivos se mantienen " "cortos, funciones para ejecutar desde otros módulos. A esos otros módulos " "se les puede fácilmente realizar pruebas unitarias y son apropiadamente re-" "utilizables." #: ../Doc/library/__main__.rst:246 msgid "" "If used, an ``if __name__ == '__main__'`` block will still work as expected " "for a ``__main__.py`` file within a package, because its ``__name__`` " "attribute will include the package's path if imported::" msgstr "" "Si se usa, un bloque ``if __name__=='__main__'`` seguirá funcionando como se " "espera para un archivo ``__main__.py`` dentro de un paquete, porque su " "atributo ``__name__`` incluirá la ruta del paquete si es importado::" #: ../Doc/library/__main__.rst:254 #, fuzzy msgid "" "This won't work for ``__main__.py`` files in the root directory of a .zip " "file though. Hence, for consistency, minimal ``__main__.py`` like the :mod:" "`venv` one mentioned below are preferred." msgstr "" "Sin embargo, esto no funcionará para archivos ``__main__.py`` en el " "directorio base de un archivo .zip. Por lo tanto, por consistencia, es " "preferible un ``__main__.py`` minimalista como el :mod:`venv` mencionado " "arriba." #: ../Doc/library/__main__.rst:260 #, fuzzy msgid "" "See :mod:`venv` for an example of a package with a minimal ``__main__.py`` " "in the standard library. It doesn't contain a ``if __name__ == '__main__'`` " "block. You can invoke it with ``python -m venv [directory]``." msgstr "" "En :mod:`venv` puedes conseguir un ejemplo de un paquete con un ``__main__." "py`` minimalista en la librería estándar. No contiene un bloque ``if " "__name__=='__main__'``. Lo puedes invocar con ``python3 -m venv " "[directorio]``." #: ../Doc/library/__main__.rst:264 msgid "" "See :mod:`runpy` for more details on the :option:`-m` flag to the " "interpreter executable." msgstr "" "Ver :mod:`runpy` para más detalles sobre el indicador :option:`-m` para el " "interprete ejecutable." #: ../Doc/library/__main__.rst:267 msgid "" "See :mod:`zipapp` for how to run applications packaged as *.zip* files. In " "this case Python looks for a ``__main__.py`` file in the root directory of " "the archive." msgstr "" "Ver :mod:`zipapp` para más información sobre como ejecutar aplicaciones " "empaquetadas como archivos *.zip*. En este caso Python busca un archivo " "``__main__.py`` en el directorio raíz del archivo comprimido." #: ../Doc/library/__main__.rst:274 msgid "``import __main__``" msgstr "``import __main__``" #: ../Doc/library/__main__.rst:276 msgid "" "Regardless of which module a Python program was started with, other modules " "running within that same program can import the top-level environment's " "scope (:term:`namespace`) by importing the ``__main__`` module. This " "doesn't import a ``__main__.py`` file but rather whichever module that " "received the special name ``'__main__'``." msgstr "" "Independientemente de con cual módulo se ha iniciado un programa de Python, " "otros módulos que están siendo ejecutados dentro del mismo programa pueden " "importar el ámbito del entorno de máximo nivel (:term:`namespace`) al " "importar el módulo ``__main__``. Esto no importa un archivo ``__main__.py`` " "pero en su lugar cualquier módulo que recibió el nombre especial " "``'__main__'``." #: ../Doc/library/__main__.rst:282 msgid "Here is an example module that consumes the ``__main__`` namespace::" msgstr "" "Acá hay un módulo ejemplo que consume el nombre de espacio ``__main__``::" #: ../Doc/library/__main__.rst:300 msgid "Example usage of this module could be as follows::" msgstr "Ejemplo del uso de este módulo puede ser::" #: ../Doc/library/__main__.rst:319 msgid "Now, if we started our program, the result would look like this:" msgstr "Si ahora iniciamos nuestro programa el resultado sería así::" #: ../Doc/library/__main__.rst:326 msgid "" "The exit code of the program would be 1, indicating an error. Uncommenting " "the line with ``my_name = \"Dinsdale\"`` fixes the program and now it exits " "with status code 0, indicating success:" msgstr "" "El código de salida del programa sería 1, indicando un error. Des-comentando " "la línea con ``my_name = \"Dinsdale\"`` arregla el programa y ahora sale con " "un código de estado 0, indicando éxito:" #: ../Doc/library/__main__.rst:335 msgid "" "Note that importing ``__main__`` doesn't cause any issues with " "unintentionally running top-level code meant for script use which is put in " "the ``if __name__ == \"__main__\"`` block of the ``start`` module. Why does " "this work?" msgstr "" "Note que importar ``__main__`` no causa ningún problema de involuntariamente " "ejecutar código de máximo nivel que ha sido pensado para uso por scripts que " "es puesto en el bloque ``if __name__==\"__main__\"`` del módulo ``start``. " "¿Por qué funciona esto?" #: ../Doc/library/__main__.rst:339 #, fuzzy msgid "" "Python inserts an empty ``__main__`` module in :data:`sys.modules` at " "interpreter startup, and populates it by running top-level code. In our " "example this is the ``start`` module which runs line by line and imports " "``namely``. In turn, ``namely`` imports ``__main__`` (which is really " "``start``). That's an import cycle! Fortunately, since the partially " "populated ``__main__`` module is present in :data:`sys.modules`, Python " "passes that to ``namely``. See :ref:`Special considerations for __main__ " "` in the import system's reference for details on how " "this works." msgstr "" "Python inserta un módulo ``__main__`` vacío en :attr:`sys.modules` al inicio " "del intérprete, y lo puebla ejecutando código de máximo nivel. En nuestro " "ejemplo este es el módulo ``start`` que corre línea a línea e importa " "``namely``. A su vez, ``namely`` importa ``__main__`` (que es en verdad " "``start``). ¡Es un ciclo de importado! Afortunadamente, como el módulo " "parcialmente poblado ``__main__`` está presente en :attr:`sys.modules`, " "Python pasa eso a ``namely``. Ver :ref:`Special considerations for __main__ " "` en la referencia del sistema para información " "detallada de como funciona." #: ../Doc/library/__main__.rst:348 msgid "" "The Python REPL is another example of a \"top-level environment\", so " "anything defined in the REPL becomes part of the ``__main__`` scope::" msgstr "" "El REPL Python es otro ejemplo de un \"entorno de máximo nivel\", por lo " "tanto, cualquier cosa definida en el REPL se hace parte del ámbito " "``__main__``::" #: ../Doc/library/__main__.rst:364 msgid "" "Note that in this case the ``__main__`` scope doesn't contain a ``__file__`` " "attribute as it's interactive." msgstr "" "Note que en este caso el ámbito ``__main__`` no contiene un atributo " "``__file__`` ya que es interactivo." #: ../Doc/library/__main__.rst:367 msgid "" "The ``__main__`` scope is used in the implementation of :mod:`pdb` and :mod:" "`rlcompleter`." msgstr "" "El ámbito ``__main__`` es utilizado en la implementación de :mod:`pdb` y :" "mod:`rlcompleter`."