code: def try_import(mod, only_modules=False):
      mod = mod.rstrip(".")
      try:
          m = __import__(mod)
      except:
          return []
      mods = mod.split(".")
      for module in mods[1:]:
          m = getattr(m, module)
  
      filename = getattr(m, "__file__", "")
      m_is_init = "__init__" in (filename or "") or filename == mod
  
      completions = []
      if (
          (not hasattr(m, "__file__"))
          or (not only_modules)
          or m_is_init
      ):
          completions.extend(
              [
                  attr
                  for attr in dir(m)
                  if is_importable(m, attr, only_modules)
              ]
          )
  
      completions.extend(getattr(m, "__all__", []))
      if m_is_init:
          completions.extend(arcadia_module_list(mod))
      completions = {
          c for c in completions if isinstance(c, string_types)
      }
      completions.discard("__init__")
      return sorted(completions)
  
imports: from __future__ import print_function
  import glob
  import inspect
  import itertools
  import os
  import re
  import sys
  from time import time
  from zipimport import zipimporter
  from IPython.core.completer import expand_user, compress_user
  from IPython.core.error import TryNext
  from IPython.utils._process_common import arg_split
  from IPython.utils.py3compat import string_types
  from IPython import get_ipython
  from __res import importer
label_desc: Use image node_id 7 for calling a global function with example usage: try_import(mod, only_modules) and returns: sorted, list