labm8.modules

Utils for handling python modules.

labm8.modules.import_foreign(name, custom_name=None)

Import a module with a custom name.

NOTE this is only needed for Python2. For Python3, import the module using the “as” keyword to declare the custom name.

For implementation details, see: http://stackoverflow.com/a/6032023

Example

To import the standard module “math” as “std_math”:

if labm8.is_python3():
import math as std_math
else:
std_math = modules.import_foreign(“math”, “std_math”)
Parameters:
  • name (str) – The name of the module to import.
  • custom_name (str, optional) – The custom name to assign the module to.
Raises:

ImportError – If the module is not found.