将ihooks移植到Python3

2024-04-26 22:31:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将一些非常古老的代码移植到python3中。 我遇到了一个函数,它试图使用ihooks加载一些其他模块。你知道吗

感兴趣的代码是:

def _getCOMModuleForLocation(self, componentFile):
    fqn = componentFile.path
    mod = self.com_modules.get(fqn)
    if mod is not None:
        return mod
    import ihooks, sys
    base_name = os.path.splitext(os.path.basename(fqn))[0]
    loader = ihooks.ModuleLoader()

    module_name_in_sys = "component:%s" % (base_name,)
    stuff = loader.find_module(base_name, [componentFile.parent.path])
    assert stuff is not None, "Couldnt find the module '%s'" % (base_name,)
    py_mod = loader.load_module( module_name_in_sys, stuff )

    # Make and remember the COM module.
    comps = FindCOMComponents(py_mod)
    mod = self.moduleFactory(comps)

    self.com_modules[fqn] = mod
    return mod

你能帮我使这段代码与python3兼容,同时保持与2.6和2.7的向后兼容性吗?你知道吗

更新

看起来我找到了如何在3.1+下工作:importlib

但3.0的问题仍然存在。你知道吗


Tags: path代码nameselfcommodbasesys