2012-05-30 50 views

回答

3

如果你看看zope.interface.interfaces module你会发现Interface类有IInterface interface definition!它记录了names方法如下:

def names(all=False): 
    """Get the interface attribute names 

    Return a sequence of the names of the attributes, including 
    methods, included in the interface definition. 

    Normally, only directly defined attributes are included. If 
    a true positional or keyword argument is given, then 
    attributes defined by base classes will be included. 
    """ 

要从而扩大你的例子:

>>> from zope.interface import Interface, Attribute 
>>> class IA(Interface): 
...  foo = Attribute("foo") 
... 
>>> IA.names() 
['foo'] 
>>> class IB(IA): 
...  bar = Attribute("bar") 
... 
>>> IB.names() 
['bar'] 
>>> IB.names(all=True) 
['foo', 'bar'] 
+0

感谢。出于某种原因,docs.zope.org上的zope.interface消失了,我没有想到要在发布问题之前检查方法签名。 – Ben

2

明白了:

IB.names(all=True) 

我想我应该在今后的检查方法签名的详细。