How to define an Interface in Python 2.2.2?

B

Boo Yah

Does Python 2.2.2 support Interface (as PHP 5 does) ?

If so, how can i define it in Py 2.2.2?

Regards,
Booyah
 
D

Doug

Boo said:
Does Python 2.2.2 support Interface (as PHP 5 does) ?

If so, how can i define it in Py 2.2.2?

Python doesn't directly support interfaces.
What most people for an interface is to create a class where
the methods raise a NotImplementedError. For example:

class MyInterface:
def method1():
raise NotImplementedError
def method2():
raise NotImplementedError

class MyClass (MyInterface):
"implements MyInterface"
def method1():
some code here...
def method2():
some code here...

But see this page for some attempts at creating interfaces
for Python: http://www.python.org/cgi-bin/moinmoin/MetaClasses
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top