代码之家  ›  专栏  ›  技术社区  ›  Enriquev

python dll swig帮助

  •  0
  • Enriquev  · 技术社区  · 14 年前

    首先,我从来没有用过SWIG,我不知道它做什么。。。

    我们有一个python库,据我所知,它使用SWIG,比如说,当我想使用这个库时,我必须把它放在python代码中:

    import pylib
    

    # This file was automatically generated by SWIG (http://www.swig.org).
    # Version 1.3.33
    #
    # Don't modify this file, modify the SWIG interface instead.
    # This file is compatible with both classic and new-style classes.
    
    import _pylib
    import new
    new_instancemethod = new.instancemethod
    

    接下来,在与pylib.py相同的目录中,有一个名为pylib.pyd的文件,我认为它是一个dll。

    我的问题是:

    class PersistentCache(_object):
        __swig_setmethods__ = {}
        __setattr__ = lambda self, name, value: _swig_setattr(self, PersistentCache, name, value)
        __swig_getmethods__ = {}
        __getattr__ = lambda self, name: _swig_getattr(self, PersistentCache, name)
        __repr__ = _swig_repr
        def __init__(self, *args): 
            this = _pylib.new_PersistentCache(*args)
            try: self.this.append(this)
            except: self.this = this
        __swig_destroy__ = _pylib.delete_PersistentCache
        __del__ = lambda self : None;
        def setProperty(*args): return _pylib.PersistentCache_setProperty(*args)
        def getProperty(*args): return _pylib.PersistentCache_getProperty(*args)
        def clear(*args): return _pylib.PersistentCache_clear(*args)
        def entries(*args): return _pylib.PersistentCache_entries(*args)
    PersistentCache_swigregister = _pylib.PersistentCache_swigregister
    PersistentCache_swigregister(PersistentCache)
    

    假设我想使用这个类或它的方法,比如:

     *args
    

    1 回复  |  直到 14 年前
        1
  •  2
  •   cecilkorik    14 年前

    SWIG是一种自动包装C/C++库的方法,因此可以从Python访问。这个库实际上是一个编译为DLL的C库。Python代码只是传递代码,都是SWIG自动生成的,你说得对,它没有多大帮助。

    如果您想知道要传递什么参数,就不应该查看Python代码,而应该查看生成它的C代码(如果有),或者查看文档(如果没有)。如果你没有这个库的任何代码或文档,那么我认为你将很难弄清楚它。。。您应该联系供应商获取文档。