Python "implements <interface>" equivalent?

Jarek Zgoda jzgoda at o2.usun.pl
Thu Oct 4 17:19:21 CEST 2007


Wojciech Gryc napisał(a):

> I'm a seasoned Java programmer and quite a big fan of interfaces...
> i.e. The idea that if I make a number of distinct classes that
> implement interface X, I can pass them all as parameters to functions
> or whatnot that require an X object.
> 
> Is there something similar in Python?

The closest thing I saw is zope.interface.

> What I'd like to do is create a feature detection system for my work
> -- specifically, a general class / interface called "Feature" and then
> subclasses that implement functions like isFeaturePresent() in all of
> their different and unique ways. I'd love to hear how I can do this in
> Python.

I am sure you wouldn't need interfaces to do such things in Python.
"Duck typing" is how we call this feature. :)

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: zgoda at jabber.aster.pl | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)



More information about the Python-list mailing list