Previous topic

mmf.examples

Next topic

mmf.examples.init_example.mod1

This Page

mmf.examples.init_example

mod1 mod1
mod2
mod3 The loading of this module is delayed by including it in the
mod4
g(x) Return x*x.

Example of a module using automatic import detection as provided by mmf.utils.init. This is the minimal __init__.py file.

Example of automatic initialization.

This is the main documentation for the module. This will be appended to any documentation provided directly in the __init__.py file.

Here we simply define the function g().

One special member can be defined here __delay__ which is a set or list of local modules that should not be imported unless explicitly requested. This can be useful for modules that are expensive to import. As an example here we delay the loading of mmf.examples.init_example.mod3.

Note

The file named mod + ‘_.py’ contains objects to be directly defined in the module. These could be included in __init__.py but we keep that simple.

>>> import mmf.examples.init_example
>>> print(mmf.examples.init_example.__doc__)
Example of a module using automatic import detection as provided by
:mod:`mmf.utils.init`.  This is the minimal `__init__.py` file.


Example of automatic initialization.

This is the main documentation for the module.  This will be appended
to any documentation provided directly in the `__init__.py` file.

Here we simply define the function :func:`g`.

One special member can be defined here `__delay__` which is a set or
list of local modules that should not be imported unless explicitly
requested.  This can be useful for modules that are expensive to
import.  As an example here we delay the loading of
:mod:`mmf.examples.init_example.mod3`.

.. note:: The file named `mod + '_.py'` contains objects to be
   directly defined in the module.  These could be included in
   `__init__.py` but we keep that simple.
...

Note that mmf.examples.init_example.mod3 was not imported because it was included in __delay__. It can be explicitly imported:

>>> from mmf.examples.init_example import * 
Starting import of mod3...
Finished importing mod3...

This fails with doctest because the module gets imported repeatedly to determine the tests.

>>> sorted(mmf.examples.init_example.__dict__.keys()) 
['__all__', '__builtins__', '__doc__', '__file__', '__name__',
 '__path__', 'g', 'mod1', 'mod2', 'mod3', 'mod4']
mmf.examples.init_example.g(x)

Return x*x.