code: def simport(modname):
      """
      Safely import a module without raising an error.
  
      Parameters
      -----------
      modname : str
                module name needed to import
  
      Returns
      --------
      tuple of (True, Module) or (False, None) depending on whether the import
      succeeded.
  
      Notes
      ------
      Wrapping this function around an iterative context or a with context would
      allow the module to be used without necessarily attaching it permanently in
      the global namespace:
  
  
          for t,mod in simport('pandas'):
              if t:
                  mod.DataFrame()
              else:
                  #do alternative behavior here
              del mod #or don't del, your call
  
      instead of:
  
          t, mod = simport('pandas')
          if t:
              mod.DataFrame()
          else:
              #do alternative behavior here
  
      The first idiom makes it work kind of a like a with statement.
      """
      try:
          exec("import {}".format(modname))
          return True, eval(modname)
      except:
          return False, None
  
file_path: pysal/pysal/lib/common.py
imports: import copy
  import sys
  import time
  import numpy
  import numpy.linalg
  import scipy
  import scipy.stats
  from libpysal.cg.kdtree import KDTree
  from scipy.spatial.distance import pdist, cdist
  import pandas
label_desc: Use image node_id 1 for calling a global function with example usage: simport(modname) and returns: True,  eval, False,  None