__init__.py 文件源码

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

项目:pupy 作者: ru-faraon 项目源码 文件源码
def GetObject(Pathname = None, Class = None, clsctx = None):
  """
    Mimic VB's GetObject() function.

    ob = GetObject(Class = "ProgID") or GetObject(Class = clsid) will
    connect to an already running instance of the COM object.

    ob = GetObject(r"c:\blah\blah\foo.xls") (aka the COM moniker syntax)
    will return a ready to use Python wrapping of the required COM object.

    Note: You must specifiy one or the other of these arguments. I know
    this isn't pretty, but it is what VB does. Blech. If you don't
    I'll throw ValueError at you. :)

    This will most likely throw pythoncom.com_error if anything fails.
  """
  if clsctx is None:
    clsctx = pythoncom.CLSCTX_ALL

  if (Pathname is None and Class is None) or \
     (Pathname is not None and Class is not None):
    raise ValueError("You must specify a value for Pathname or Class, but not both.")

  if Class is not None:
    return GetActiveObject(Class, clsctx)
  else:
    return Moniker(Pathname, clsctx)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号