What is the purpose of Zope Interfaces?

0 votes
I have recently started using Zope interfaces in my code and they are only documentation. I use them to specify what attributes the class should possess, explicitly implement them in the appropriate classes and explicitly check for them where I expect one. But What should I do if I would like them to do more such as verify that the class has implemented the interface, instead of just verifying that I have said that the class implements the interface. I have read the zope wiki a couple of times, but still cannot see much more use for interfaces than what I am currently doing.  What else can you use these interfaces for, and how do you use them for more?

Can anyone help me with this?
Feb 28 in Python by ana1504.k
• 5,910 points
18 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
You can actually test if your object or class implements your interface. For that you can use verify module.

For example:

>>> from zope.interface import Interface, Attribute, implements
>>> class IFoo(Interface):
...     x = Attribute("The X attribute")
...     y = Attribute("The Y attribute")

>>> class Foo(object):
...     implements(IFoo)
...     x = 1
...     def __init__(self):
...         self.y = 2

>>> from zope.interface.verify import verifyObject
>>> verifyObject(IFoo, Foo())
True

>>> from zope.interface.verify import verifyClass
>>> verifyClass(IFoo, Foo)
True
answered Feb 28 by SDeb
• 9,380 points

Related Questions In Python

0 votes
1 answer

What is the purpose of self?

The reason you need to use self. ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 56,100 points
16 views
0 votes
0 answers

what is the purpose of the argument 'end' in the print function?

is it necessary to use this argument ...READ MORE

May 9 in Python by Waseem
• 1,870 points
3 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,420 points
948 views
0 votes
2 answers

What is the use of Python language?

python is general purpose programming language.it very ...READ MORE

answered Mar 15 in Python by rajesh kumar
19 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 920 points
19 views
0 votes
1 answer

What is the purpose of inner class in Python?

Advantages of inner class: Logical grouping of classes: ...READ MORE

answered Feb 7 in Python by SDeb
• 9,380 points
66 views
0 votes
1 answer

Is arr.__len__() the preferred way to get the length of an array in Python?

my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 9,380 points
22 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.