Changeset 24


Ignore:
Timestamp:
26/06/09 10:00:45 (4 years ago)
Author:
facundobatista
Message:

Más lineas!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/traducidos/modules.rst

    r22 r24  
    475475de módulos largos. 
    476476 
    477 The only solution is for the package author to provide an explicit index of the 
    478 package.  The import statement uses the following convention: if a package's 
    479 :file:`__init__.py` code defines a list named ``__all__``, it is taken to be the 
    480 list of module names that should be imported when ``from package import *`` is 
    481 encountered.  It is up to the package author to keep this list up-to-date when a 
    482 new version of the package is released.  Package authors may also decide not to 
    483 support it, if they don't see a use for importing \* from their package.  For 
    484 example, the file :file:`sounds/effects/__init__.py` could contain the following 
    485 code:: 
     477La única solución es que el autor del paquete provea un índice explícito del 
     478paquete.  La declaración ``import`` usa la siguiente convención: si el código 
     479del :file:`__init__.py` de un paquete define una lista llamada ``__all__``, se 
     480toma como la lista de los nombres de módulos que deberían ser importados cuando 
     481se hace ``from package import *``.  Es tarea del autor del paquete mantener 
     482actualizada esta lista cuando se libera una nueva versión del paquete.  Los 
     483autores de paquetes podrían decidir no soportarlo, si no ven un uso para 
     484importar \* en sus paquetes.  Por ejemplo, el archivo 
     485:file:`sounds/effects/__init__.py` podría contener el siguiente código:: 
    486486 
    487487   __all__ = ["echo", "surround", "reverse"] 
    488488 
    489 This would mean that ``from sound.effects import *`` would import the three 
    490 named submodules of the :mod:`sound` package. 
    491  
    492 If ``__all__`` is not defined, the statement ``from sound.effects import *`` 
    493 does *not* import all submodules from the package :mod:`sound.effects` into the 
    494 current namespace; it only ensures that the package :mod:`sound.effects` has 
    495 been imported (possibly running any initialization code in :file:`__init__.py`) 
    496 and then imports whatever names are defined in the package.  This includes any 
    497 names defined (and submodules explicitly loaded) by :file:`__init__.py`.  It 
    498 also includes any submodules of the package that were explicitly loaded by 
    499 previous import statements.  Consider this code:: 
     489Esto significaría que ``from sound.effects import *`` importaría esos tres 
     490submódulos del paquete :mod:`sound`. 
     491 
     492 
     493Si no se define ``__all__``, la declaración ``from sound.effects import *`` 
     494*no* importa todos los submódulos del paquete :mod:`sound.effects` al espacio 
     495de nombres actual; sólo se asegura que se haya importado el paquete 
     496:mod:`sound.effects` (posiblemente ejecutando algún código de inicialización 
     497que haya en :file:`__init__.py`) y luego importa aquellos nombres que estén 
     498definidos en el paquete.  Esto incluye cualquier nombre definido (y submódulos 
     499explícitamente cargados) por :file:`__init__.py`.  También incluye cualquier 
     500submódulo del paquete que pudiera haber sido explícitamente cargado por 
     501declaraciones ``import`` previas.  Considerá este código:: 
    500502 
    501503   import sound.effects.echo 
     
    503505   from sound.effects import * 
    504506 
    505 In this example, the echo and surround modules are imported in the current 
    506 namespace because they are defined in the :mod:`sound.effects` package when the 
    507 ``from...import`` statement is executed.  (This also works when ``__all__`` is 
    508 defined.) 
     507En este ejemplo, los módulos *echo* y *surround* se importan en el espacio de 
     508nombre actual porque están definidos en el paquete :mod:`sound.effects` cuando 
     509se ejecuta la declaración ``from...import``.  (Esto también funciona cuando se 
     510define ``__all__``). 
    509511 
    510512Note that in general the practice of importing ``*`` from a module or package is 
Note: See TracChangeset for help on using the changeset viewer.