Importando módulos
******************

PyObject *PyImport_ImportModule(const char *name)
    *Return value: New reference.** Part of the Stable ABI.*

   This is a wrapper around "PyImport_Import()" which takes a const
   char* as an argument instead of a PyObject*.

PyObject *PyImport_ImportModuleNoBlock(const char *name)
    *Return value: New reference.** Part of the Stable ABI.*

   Esta función es un alias obsoleto de "PyImport_ImportModule()".

   Distinto en la versión 3.3: Esta función solía fallar
   inmediatamente cuando el bloqueo de importación era retenido por
   otro hilo. Sin embargo, en Python 3.3, el esquema de bloqueo cambió
   a bloqueos por módulo para la mayoría de los propósitos, por lo que
   el comportamiento especial de esta función ya no es necesario.

   Deprecated since version 3.13, will be removed in version 3.15: Use
   "PyImport_ImportModule()" instead.

PyObject *PyImport_ImportModuleEx(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
    *Return value: New reference.*

   Importa un módulo. Esto se describe mejor haciendo referencia a la
   función Python incorporada "__import__()".

   El valor de retorno es una nueva referencia al módulo importado o
   paquete de nivel superior, o "NULL" con una excepción establecida
   en caso de error. Al igual que para "__import__()", el valor de
   retorno cuando se solicitó un submódulo de un paquete normalmente
   es el paquete de nivel superior, a menos que se proporcione un
   *fromlist* no vacío.

   Las importaciones que fallan eliminan objetos de módulo
   incompletos, como con "PyImport_ImportModule()".

PyObject *PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.7.*

   Importa un módulo. Esto se describe mejor haciendo referencia a la
   función Python incorporada "__import__()", ya que la función
   estándar "__import__()" llama a esta función directamente.

   El valor de retorno es una nueva referencia al módulo importado o
   paquete de nivel superior, o "NULL" con una excepción establecida
   en caso de error. Al igual que para "__import__()", el valor de
   retorno cuando se solicitó un submódulo de un paquete normalmente
   es el paquete de nivel superior, a menos que se proporcione un
   *fromlist* no vacío.

   Added in version 3.3.

PyObject *PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
    *Return value: New reference.** Part of the Stable ABI.*

   Similar a "PyImport_ImportModuleLevelObject()", pero el nombre es
   una cadena de caracteres codificada UTF-8 en lugar de un objeto
   Unicode.

   Distinto en la versión 3.3: Los valores negativos para *level* ya
   no se aceptan.

PyObject *PyImport_Import(PyObject *name)
    *Return value: New reference.** Part of the Stable ABI.*

   Esta es una interfaz de nivel superior que llama a la "función de
   enlace de importación" actual (con un nivel explícito de 0, que
   significa importación absoluta). Invoca la función "__import__()"
   de las "__builtins__" de los globales (*globals*) actuales. Esto
   significa que la importación se realiza utilizando los ganchos de
   importación instalados en el entorno actual.

   Esta función siempre usa importaciones absolutas.

PyObject *PyImport_ReloadModule(PyObject *m)
    *Return value: New reference.** Part of the Stable ABI.*

   Recarga un módulo. Retorna una nueva referencia al módulo
   recargado, o "NULL" con una excepción establecida en caso de error
   (el módulo todavía existe en este caso).

PyObject *PyImport_AddModuleRef(const char *name)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.13.*

   Return the module object corresponding to a module name.

   The *name* argument may be of the form "package.module". First
   check the modules dictionary if there's one there, and if not,
   create a new one and insert it in the modules dictionary.

   Return a *strong reference* to the module on success. Return "NULL"
   with an exception set on failure.

   The module name *name* is decoded from UTF-8.

   This function does not load or import the module; if the module
   wasn't already loaded, you will get an empty module object. Use
   "PyImport_ImportModule()" or one of its variants to import a
   module. Package structures implied by a dotted name for *name* are
   not created if not already present.

   Added in version 3.13.

PyObject *PyImport_AddModuleObject(PyObject *name)
    *Return value: Borrowed reference.** Part of the Stable ABI since
   version 3.7.*

   Similar to "PyImport_AddModuleRef()", but return a *borrowed
   reference* and *name* is a Python "str" object.

   Added in version 3.3.

PyObject *PyImport_AddModule(const char *name)
    *Return value: Borrowed reference.** Part of the Stable ABI.*

   Similar to "PyImport_AddModuleRef()", but return a *borrowed
   reference*.

PyObject *PyImport_ExecCodeModule(const char *name, PyObject *co)
    *Return value: New reference.** Part of the Stable ABI.*

   Given a module name (possibly of the form "package.module") and a
   code object read from a Python bytecode file or obtained from the
   built-in function "compile()", load the module.  Return a new
   reference to the module object, or "NULL" with an exception set if
   an error occurred.  *name* is removed from "sys.modules" in error
   cases, even if *name* was already in "sys.modules" on entry to
   "PyImport_ExecCodeModule()".  Leaving incompletely initialized
   modules in "sys.modules" is dangerous, as imports of such modules
   have no way to know that the module object is an unknown (and
   probably damaged with respect to the module author's intents)
   state.

   The module's "__spec__" and "__loader__" will be set, if not set
   already, with the appropriate values.  The spec's loader will be
   set to the module's "__loader__" (if set) and to an instance of
   "SourceFileLoader" otherwise.

   The module's "__file__" attribute will be set to the code object's
   "co_filename".  If applicable, "__cached__" will also be set.

   Esta función volverá a cargar el módulo si ya se importó. Consulte
   "PyImport_ReloadModule()" para conocer la forma prevista de volver
   a cargar un módulo.

   Si *name* apunta a un nombre punteado de la forma "package.module",
   cualquier estructura de paquete que no se haya creado aún no se
   creará.

   Ver también "PyImport_ExecCodeModuleEx()" y
   "PyImport_ExecCodeModuleWithPathnames()".

   Distinto en la versión 3.12: The setting of "__cached__" and
   "__loader__" is deprecated. See "ModuleSpec" for alternatives.

PyObject *PyImport_ExecCodeModuleEx(const char *name, PyObject *co, const char *pathname)
    *Return value: New reference.** Part of the Stable ABI.*

   Like "PyImport_ExecCodeModule()", but the "__file__" attribute of
   the module object is set to *pathname* if it is non-"NULL".

   Ver también "PyImport_ExecCodeModuleWithPathnames()".

PyObject *PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, PyObject *cpathname)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.7.*

   Like "PyImport_ExecCodeModuleEx()", but the "__cached__" attribute
   of the module object is set to *cpathname* if it is non-"NULL".  Of
   the three functions, this is the preferred one to use.

   Added in version 3.3.

   Distinto en la versión 3.12: Setting "__cached__" is deprecated.
   See "ModuleSpec" for alternatives.

PyObject *PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, const char *pathname, const char *cpathname)
    *Return value: New reference.** Part of the Stable ABI.*

   Como "PyImport_ExecCodeModuleObject()", pero *name*, *pathname* y
   *cpathname* son cadenas de caracteres codificadas UTF-8. También se
   intenta averiguar cuál debe ser el valor de *pathname* de
   *cpathname* si el primero se establece en "NULL".

   Added in version 3.2.

   Distinto en la versión 3.3: Uses "imp.source_from_cache()" in
   calculating the source path if only the bytecode path is provided.

   Distinto en la versión 3.12: No longer uses the removed "imp"
   module.

long PyImport_GetMagicNumber()
    * Part of the Stable ABI.*

   Retorna el número mágico para los archivos de *bytecode* de Python
   (también conocido como archivos ".pyc"). El número mágico debe
   estar presente en los primeros cuatro bytes del archivo de código
   de bytes, en orden de bytes *little-endian*. Retorna "-1" en caso
   de error.

   Distinto en la versión 3.3: Retorna un valor de "-1" en caso de
   error.

const char *PyImport_GetMagicTag()
    * Part of the Stable ABI.*

   Retorna la cadena de caracteres de etiqueta mágica para nombres de
   archivo de código de bytes Python en formato **PEP 3147**. Tenga en
   cuenta que el valor en "sys.implementation.cache_tag" es
   autoritario y debe usarse en lugar de esta función.

   Added in version 3.2.

PyObject *PyImport_GetModuleDict()
    *Return value: Borrowed reference.** Part of the Stable ABI.*

   Retorna el diccionario utilizado para la administración del módulo
   (también conocido como "sys.modules"). Tenga en cuenta que esta es
   una variable por intérprete.

PyObject *PyImport_GetModule(PyObject *name)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.8.*

   Retorna el módulo ya importado con el nombre dado. Si el módulo aún
   no se ha importado, retorna "NULL" pero no establece un error.
   Retorna "NULL" y establece un error si falla la búsqueda.

   Added in version 3.7.

PyObject *PyImport_GetImporter(PyObject *path)
    *Return value: New reference.** Part of the Stable ABI.*

   Return a finder object for a "sys.path"/"pkg.__path__" item *path*,
   possibly by fetching it from the "sys.path_importer_cache" dict.
   If it wasn't yet cached, traverse "sys.path_hooks" until a hook is
   found that can handle the path item.  Return "None" if no hook
   could; this tells our caller that the *path based finder* could not
   find a finder for this path item. Cache the result in
   "sys.path_importer_cache". Return a new reference to the finder
   object.

int PyImport_ImportFrozenModuleObject(PyObject *name)
    * Part of the Stable ABI since version 3.7.*

   Carga un módulo congelado llamado *name*. Retorna "1" para el
   éxito, "0" si no se encuentra el módulo y "-1" con una excepción
   establecida si falla la inicialización. Para acceder al módulo
   importado con una carga exitosa, use "PyImport_ImportModule()".
   (Tenga en cuenta el nombre inapropiado --- esta función volvería a
   cargar el módulo si ya se importó).

   Added in version 3.3.

   Distinto en la versión 3.4: El atributo "__file__" ya no está
   establecido en el módulo.

int PyImport_ImportFrozenModule(const char *name)
    * Part of the Stable ABI.*

   Similar a "PyImport_ImportFrozenModuleObject()", pero el nombre es
   una cadena de caracteres codificada UTF-8 en lugar de un objeto
   Unicode.

struct _frozen

   Esta es la definición del tipo de estructura para los descriptores
   de módulos congelados, según lo generado con la herramienta
   **freeze** (ver "Tools/freeze" en la distribución de código fuente
   de Python). Su definición, que se encuentra en "Include/import.h",
   es:

      struct _frozen {
          const char *name;
          const unsigned char *code;
          int size;
          bool is_package;
      };

   Distinto en la versión 3.11: El nuevo campo "is_package" indica si
   el módulo es un paquete o no. Esto sustituye a la configuración del
   campo "size" con un valor negativo.

const struct _frozen *PyImport_FrozenModules

   Este puntero se inicializa para apuntar a un arreglo de registros
   "_frozen", terminado por uno cuyos registros son todos "NULL" o
   cero. Cuando se importa un módulo congelado, se busca en esta
   tabla. El código de terceros podría jugar con esto para
   proporcionar una colección de módulos congelados creada
   dinámicamente.

int PyImport_AppendInittab(const char *name, PyObject *(*initfunc)(void))
    * Part of the Stable ABI.*

   Agrega un solo módulo a la tabla existente de módulos incorporados.
   Este es un contenedor conveniente "PyImport_ExtendInittab()", que
   retorna "-1" si la tabla no se puede extender. El nuevo módulo se
   puede importar con el nombre *name*, y utiliza la función
   *initfunc* como la función de inicialización llamada en el primer
   intento de importación. Esto debería llamarse antes de
   "Py_Initialize()".

struct _inittab

   Structure describing a single entry in the list of built-in
   modules. Programs which embed Python may use an array of these
   structures in conjunction with "PyImport_ExtendInittab()" to
   provide additional built-in modules. The structure consists of two
   members:

   const char *name

      The module name, as an ASCII encoded string.

   PyObject *(*initfunc)(void)

      Initialization function for a module built into the interpreter.

int PyImport_ExtendInittab(struct _inittab *newtab)

   Add a collection of modules to the table of built-in modules.  The
   *newtab* array must end with a sentinel entry which contains "NULL"
   for the "name" field; failure to provide the sentinel value can
   result in a memory fault. Returns "0" on success or "-1" if
   insufficient memory could be allocated to extend the internal
   table.  In the event of failure, no modules are added to the
   internal table.  This must be called before "Py_Initialize()".

   Si Python es inicializado múltiples veces, se debe llamar
   "PyImport_AppendInittab()" o "PyImport_ExtendInittab()" antes de
   cada inicialización de Python.

struct _inittab *PyImport_Inittab

   The table of built-in modules used by Python initialization. Do not
   use this directly; use "PyImport_AppendInittab()" and
   "PyImport_ExtendInittab()" instead.

PyObject *PyImport_ImportModuleAttr(PyObject *mod_name, PyObject *attr_name)
    *Return value: New reference.*

   Import the module *mod_name* and get its attribute *attr_name*.

   Names must be Python "str" objects.

   Helper function combining "PyImport_Import()" and
   "PyObject_GetAttr()". For example, it can raise "ImportError" if
   the module is not found, and "AttributeError" if the attribute
   doesn't exist.

   Added in version 3.14.

PyObject *PyImport_ImportModuleAttrString(const char *mod_name, const char *attr_name)
    *Return value: New reference.*

   Similar to "PyImport_ImportModuleAttr()", but names are UTF-8
   encoded strings instead of Python "str" objects.

   Added in version 3.14.
