On Wed, Dec 12, 2007 at 02:06:08PM +0800, 曹星明 wrote: > I'm a newbie to the zope 3. Today I was at a loss because I found all of the > names of the interfaces are the same 'InterfaceClass'. > >>> from zope.interface.interface import InterfaceClass > >>> from zope.component import interfaces > >>> for x in dir(interfaces): > >>> obj = getattr(m,x) > >>> if isinstance(obj, InterfaceClass): > >>> obj.__class__.__name__ > > InterfaceClass > InterfaceClass > ...... > ...... > InterfaceClass > InterfaceClass > > who can tell me why?
Because interfaces are objects of class InterfaceClass. > How can I get the real name of the interface? Forget the __class__. >>> for x in dir(interfaces): ... obj = getattr(interfaces, x) ... if isinstance(obj, InterfaceClass): ... obj.__name__ I'd also suggest using IInterface instead of InterfaceClass to distinguish interfaces from other objects: >>> from zope.interface.interfaces import IInterface >>> for x in sorted(dir(interfaces)): ... obj = getattr(interfaces, x) ... if IInterface.providedBy(obj): ... obj.__name__ HTH, Marius Gedminas -- C is for Cookies. Perl is even better for Cookies.
Description: Digital signature
_______________________________________________ Zope3-users mailing list Zope3firstname.lastname@example.org http://mail.zope.org/mailman/listinfo/zope3-users