[Zope3-Users] Why all of the names of the interfaces in the
zope3 are the same 'InterfaceClass'?
Marius Gedminas
mgedmin at b4net.lt
Wed Dec 12 05:16:22 EST 2007
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20071212/c6be0faa/attachment.bin
More information about the Zope3-users
mailing list