8000 Traddución de library/importlib by Alfareiza · Pull Request #3364 · python/python-docs-es · GitHub
[go: up one dir, main page]

Skip to content

Traddución de library/importlib #3364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 3.13
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
traduciendo entradas pendientes
  • Loading branch information
Alfareiza committed Jan 29, 2025
commit 204d459e250b26da998ab0af11df065565c17b24
115 changes: 114 additions & 1 deletion library/importlib.po
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ msgid ""
"except NameError:\n"
" cache = {}"
msgstr ""
"try:\n"
"cache\n"
"except NameError:\n"
"cache = {}"

#: ../Doc/library/importlib.rst:187
msgid ""
Expand Down Expand Up @@ -496,6 +500,15 @@ msgid ""
" +-- FileLoader\n"
" +-- SourceLoader"
msgstr ""
"object\n"
"+-- MetaPathFinder\n"
"+-- PathEntryFinder\n"
"+-- Loader\n"
"+-- ResourceLoader --------+\n"
"+-- InspectLoader |\n"
"+-- ExecutionLoader --+\n"
"+-- FileLoader\n"
"+-- SourceLoader"

#: ../Doc/library/importlib.rst:240
msgid "An abstract base class representing a :term:`meta path finder`."
Expand Down Expand Up @@ -2502,7 +2515,7 @@ msgid ""
msgstr ""
"import importlib\n"
"\n"
"itertools = importlib.import_module(itertools)"
"itertools = importlib.import_module('itertools')"

#: ../Doc/library/importlib.rst:1550
msgid "Checking if a module can be imported"
Expand Down Expand Up @@ -2543,6 +2556,22 @@ msgid ""
"else:\n"
" print(f\"can't find the {name!r} module\")"
msgstr ""
"import importlib.util\n"
"import sys\n"
"\n"
"# Con fines ilustrativos.\n"
"name = 'itertools'\n"
"\n"
"if name in sys.modules:\n"
"print(f\"{name!r} already in sys.modules\")\n"
"elif (spec := importlib.util.find_spec(name)) is not None:\n"
"# Si eligió realizar la importación real ...\n"
"module = importlib.util.module_from_spec(spec)\n"
"sys.modules[name] = module\n"
"spec.loader.exec_module(module)\n"
"print(f\"{name!r} ha sido importado\")\n"
"else:\n"
"print(f\"no puede ser encontrado el módulo {name!r}\")"

#: ../Doc/library/importlib.rst:1578
msgid "Importing a source file directly"
Expand Down Expand Up @@ -2594,6 +2623,25 @@ msgid ""
"# Similar outcome as `import json`.\n"
"json = import_from_path(module_name, file_path)"
msgstr ""
"import importlib.util\n"
"import sys\n"
"\n"
"\n"
"def import_from_path(module_name, file_path):\n"
"spec = importlib.util.spec_from_file_location(module_name, file_path)\n"
"module = importlib.util.module_from_spec(spec)\n"
"sys.modules[module_name] = module\n"
"spec.loader.exec_module(module)\n"
"return module\n"
"\n"
"\n"
"# Sólo con fines ilustrativos. (el uso de `json` es arbitrario).\n"
"import json\n"
"file_path = json.__file__\n"
"module_name = json.__name__\n"
"\n"
"# Resultado similar a `import json`.\n"
"json = import_from_path(module_name, file_path)"

#: ../Doc/library/importlib.rst:1611
msgid "Implementing lazy imports"
Expand Down Expand Up @@ -2622,6 +2670,22 @@ msgid ""
">>> lazy_typing.TYPE_CHECKING\n"
"False"
msgstr ""
">>> import importlib.util\n"
">>> import sys\n"
">>> def lazy_import(name):\n"
"...spec = importlib.util.find_spec(name)\n"
"...loader = importlib.util.LazyLoader(spec.loader)\n"
"...spec.loader = loader\n"
"...module = importlib.util.module_from_spec(spec)\n"
"...sys.modules[name] = module\n"
"...loader.exec_module(module)\n"
"...return module\n"
"...\n"
">>> lazy_typing = lazy_import(\"typing\")\n"
">>> #lazy_typing es un objeto de módulo real,\n"
">>> #pero aún no está cargado en la memoria.\n"
">>> lazy_typing.TYPE_CHECKING\n"
"False"

#: ../Doc/library/importlib.rst:1634
msgid "Setting up an importer"
Expand Down Expand Up @@ -2675,6 +2739,26 @@ msgid ""
"# of priority.\n"
"sys.path_hooks.append(SpamPathEntryFinder.path_hook(loader_details))"
msgstr ""
"import importlib.machinery\n"
"import sys\n"
"\n"
"# Sólo con fines ilustrativos.\n"
"SpamMetaPathFinder = importlib.machinery.PathFinder\n"
"SpamPathEntryFinder = importlib.machinery.FileFinder\n"
"detalles_del_cargador = (importlib.machinery.SourceFileLoader,\n"
"importlib.machinery.SOURCE_SUFFIXES)\n"
"\n"
"# Configuración de un meta buscador de rutas.\n"
"# Asegúrese de c 8000 olocar el buscador en la ubicación adecuada en la lista en términos "
"de\n"
"# prioridad.\n"
"sys.meta_path.append(SpamMetaPathFinder)\n"
"\n"
"# Configuración de un buscador de entradas de ruta.\n"
"# Asegúrese de colocar el gancho de ruta en la ubicación adecuada en la lista en "
"términos\n"
"# de prioridad.\n"
"sys.path_hooks.append(SpamPathEntryFinder.path_hook(detalles_del_cargador))"

#: ../Doc/library/importlib.rst:1668
msgid "Approximating :func:`importlib.import_module`"
Expand Down Expand Up @@ -2725,6 +2809,35 @@ msgid ""
" setattr(parent_module, child_name, module)\n"
" return module"
msgstr ""
"import importlib.util\n"
"import sys\n"
"\n"
"def import_module(name, package=None):\n"
"\"\"\"Una implementación aproximada de la importación.\"\"\"\n"
"nombre_absoluto = importlib.util.resolve_name(name, package)\n"
"try:\n"
"return sys.modules[nombre_absoluto]\n"
"except KeyError:\n"
"pass\n"
"\n"
"path = None\n"
"if '.' in nombre_absoluto:\n"
"parent_name, _, child_name = nombre_absoluto.rpartition('.')\n"
"parent_module = import_module(parent_name)\n"
"path = parent_module.__spec__.submodule_search_locations\n"
"for finder in sys.meta_path:\n"
"spec = finder.find_spec(nombre_absoluto, path)\n"
"if spec is not None:\n"
"break\n"
"else:\n"
"msg = f'Ningún módulo llamado {nombre_absoluto!r}'\n"
"raise ModuleNotFoundError(msg, name=nombre_absoluto)\n"
"module = importlib.util.module_from_spec(spec)\n"
"sys.modules[nombre_absoluto] = module\n"
"spec.loader.exec_module(module)\n"
"if path is not None:\n"
"setattr(parent_module, child_name, module)\n"
"return module"

#: ../Doc/library/importlib.rst:443
msgid "universal newlines"
Expand Down
0