inspectutils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:python-fire 作者: google 项目源码 文件源码
def GetFileAndLine(component):
  """Returns the filename and line number of component.

  Args:
    component: A component to find the source information for, usually a class
        or routine.
  Returns:
    filename: The name of the file where component is defined.
    lineno: The line number where component is defined.
  """
  if inspect.isbuiltin(component):
    return None, None

  try:
    filename = inspect.getsourcefile(component)
  except TypeError:
    return None, None

  try:
    unused_code, lineindex = inspect.findsource(component)
    lineno = lineindex + 1
  except IOError:
    lineno = None

  return filename, lineno
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号