parameters: (module, requiredFor="use the full functionality")
return_statement: return mod
docstring: Import and return module only if it exists.
  
      If `module` cannot be imported, a warning is printed followed by the
      `requiredFor` string. Otherwise, the imported `module` will be returned.
      This function should be used to import optional dependencies in order to
      avoid repeated try/except statements.
  
      Parameters
      ----------
      module : str
          Name of the module to be imported.
      requiredFor : str, optional
          Info string for the purpose of the dependency.
  
      Examples
      --------
      >>> import pygimli as pg
      >>> pg = pg.optImport("pygimli")
      >>> pg.__name__
      'pygimli'
      >>> pg.optImport("doesNotExist", requiredFor="do something special")
      No module named 'doesNotExist'.
      You need to install this optional dependency to do something special.
docstring_summary: Import and return module only if it exists.
docstring_tokens: Import and return module only if it exists .
function: def optImport(module, requiredFor="use the full functionality"):
      """Import and return module only if it exists.
  
      If `module` cannot be imported, a warning is printed followed by the
      `requiredFor` string. Otherwise, the imported `module` will be returned.
      This function should be used to import optional dependencies in order to
      avoid repeated try/except statements.
  
      Parameters
      ----------
      module : str
          Name of the module to be imported.
      requiredFor : str, optional
          Info string for the purpose of the dependency.
  
      Examples
      --------
      >>> import pygimli as pg
      >>> pg = pg.optImport("pygimli")
      >>> pg.__name__
      'pygimli'
      >>> pg.optImport("doesNotExist", requiredFor="do something special")
      No module named 'doesNotExist'.
      You need to install this optional dependency to do something special.
      """
      # set default message for common imports
      if not requiredFor and "matplotlib" in module:
          requiredFor = "visualize 2D content"
  
      if module.count(".") > 2:
          raise ImportError("Can only import modules and sub-packages.")
  
      mod = None
      try:
          mod = import_module(module)
      except ImportError:
          msg = ("No module named \'%s\'.\nYou need to install this optional "
                 "dependency to %s.")
          print(msg % (module, requiredFor))
          # exception would be better her but then the test fails
          # raise Exception(msg % (module, requiredFor))
  
      return mod
function_tokens: def optImport ( module , requiredFor = "use the full functionality" ) : # set default message for common imports if not requiredFor and "matplotlib" in module : requiredFor = "visualize 2D content" if module . count ( "." ) > 2 : raise ImportError ( "Can only import modules and sub-packages." ) mod = None try : mod = import_module ( module ) except ImportError : msg = ( "No module named \'%s\'.\nYou need to install this optional " "dependency to %s." ) print ( msg % ( module , requiredFor ) ) # exception would be better her but then the test fails # raise Exception(msg % (module, requiredFor)) return mod