code: def get_submodules(mod):
      
      def catch_exceptions(module):
          pass
      try:
          m = __import__(mod)
          submodules = [mod]
          submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.',
                                          catch_exceptions)
          for sm in submods:
              sm_name = sm[1]
              submodules.append(sm_name)
      except ImportError:
          return []
      except:
          return [mod]
      
      return submodules
docs: Get all submodules of a given module