[prev in list] [next in list] [prev in thread] [next in thread] 

List:       zope3-users
Subject:    Re: [Zope3-Users] Why all of the names of the interfaces in the
From:       Marius Gedminas <mgedmin () b4net ! lt>
Date:       2007-12-12 10:16:22
Message-ID: 20071212101622.GB11158 () platonas
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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.

["signature.asc" (application/pgp-signature)]

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic