include package

include.disable(identifier, children_only=False)

Disable an include type

Parameters:
  • identifier – module or name of the include type
  • children_only – disable the include type only for child processes, not the current process

The identifier can be specified in multiple ways to disable an include type. See disable() for details.

include.enable(identifier, exclude_children=False)

Enable a previously disabled include type

Parameters:
  • identifier – module or name of the include type
  • exclude_children – disable the include type only for child processes, not the current process

The identifier can be specified in multiple ways to disable an include type. See disable() for details.

include.path(file_path)

Include module code from a file identified by its path

Parameters:file_path (str) – path to a file containing module code
Returns:the imported module
Return type:module

Comparable to execfile, but respects the rules and constraints of modules. If invoked again with the same file_path, the same module is returned.

import include
my_config = include.path('/etc/sysconfig/app_conf.py')
include.source(source_code)

Include module code directly from a string

Parameters:source_code (str) – source code of the module
Returns:the imported module
Return type:module

Comparable to exec in a separate globals namespace, but respects the rules and constraints of modules. If invoked again with the same source_code, the same module is returned.

>>> import include
>>> my_module = include.source(
>>> """
... def foo():
...      return {constant}
... """.format(constant=3))
>>> my_module.foo() == 3
True