code: def import_file(filename, name=None):
      
      # Specifying a traditional dot-separated fully qualified name here
      # results in a number of "Parent module 'astropy' not found while
      # handling absolute import" warnings.  Using the same name, the
      # namespaces of the modules get merged together.  So, this
      # generates an underscore-separated name which is more likely to
      # be unique, and it doesn't really matter because the name isn't
      # used directly here anyway.
      mode = 'r'
  
      if name is None:
          basename = os.path.splitext(filename)[0]
          name = '_'.join(os.path.relpath(basename).split(os.sep)[1:])
  
      if not os.path.exists(filename):
          raise ImportError('Could not import file {0}'.format(filename))
  
      if import_machinery:
          loader = import_machinery.SourceFileLoader(name, filename)
          mod = loader.load_module()
      else:
          with open(filename, mode) as fd:
              mod = imp.load_module(name, fd, filename, ('.py', mode, 1))
  
      return mod
docs: Imports a module from a single file as if it doesn't belong to a
      particular package.
  
      The returned module will have the optional ``name`` if given, or else
      a name generated from the filename.