Interfaces in python

Discussion in 'Python' started by Thomas Weholt, May 6, 2004.

  1. Hi,

    I'm looking for a good clean explanation on how to implement interfaces in
    python. My project uses Twisted so I could use their
    interface-implementation, but I'm wondering if this is a portable solution
    or if it needs Twisted. What I mean is can I use my interface-dependant code
    if I decide to use something else than Twisted later?

    I've searched in google, and found stuff like
    http://c2.com/cgi/wiki?InterfacesInPython and read the part about
    interfaces, components and adapters in the Twisted-docs, but this is
    allready what I'm doing now. Stuff like :

    class IPerson:
    def __init__(self, name):
    self.name = name
    def say_hello(self):
    raise 'Override me in your implementation'

    class Man(IPerson):
    def say_hello(self):
    return "Hello, my name is %s and I'm a man"

    class Woman(IPerson):
    def say_hello(self):
    return "Hello, my name is %s and I'm a woman"

    ( Idiotic example I know, but it illustrates what I've been doing so far )

    What I need to know is if there are other ways of doing this, better ways
    which gives me more control, more features etc.

    Any links to good material related to interfaces in python would be
    appreciated.

    Thomas
    Thomas Weholt, May 6, 2004
    #1
    1. Advertising

  2. Thomas Weholt

    Yermat Guest

    Thomas Weholt a écrit :
    > Hi,
    >
    > I'm looking for a good clean explanation on how to implement interfaces in
    > python. My project uses Twisted so I could use their
    > interface-implementation, but I'm wondering if this is a portable solution
    > or if it needs Twisted. What I mean is can I use my interface-dependant code
    > if I decide to use something else than Twisted later?
    >
    > I've searched in google, and found stuff like
    > http://c2.com/cgi/wiki?InterfacesInPython and read the part about
    > interfaces, components and adapters in the Twisted-docs, but this is
    > allready what I'm doing now. Stuff like :
    >[...]


    Look at archive. There was already lot's of discussion about interfaces...
    http://groups.google.fr/groups?q=interfaces group:comp.lang.python

    In fact, in python, you don't need interfaces !
    But you can simulate if you really want them...

    --
    Yermat
    Yermat, May 6, 2004
    #2
    1. Advertising

  3. Thomas Weholt

    Doug Holton Guest

    Thomas Weholt wrote:
    > Hi,
    >
    > I'm looking for a good clean explanation on how to implement interfaces in
    > python.


    See the links to interfaces examples on this page:
    http://www.python.org/cgi-bin/moinmoin/MetaClasses

    Sounds like you might want to check out pyprotocols. Note though when
    installing it you have to change a setting in the setup.py file manually
    if you don't have a C compiler set up. It uses the C compiler if
    available to optimize some things.
    Doug Holton, May 6, 2004
    #3
  4. "Thomas Weholt" <> writes:

    > Any links to good material related to interfaces in python would be
    > appreciated.


    Come to EuroPython! There are going to be several talks on this
    topic. Look here for a start:

    http://www.europython.org/conferences/epc2004/info/talks/acceptedTalksOverview

    Cheers,
    mwh

    --
    I'm not particularly fond of singing GSTQ because she stands for
    some things I don't, but it's not really worth letting politics
    getting in the way of a good bawling. -- Dan Sheppard, ucam.chat
    Michael Hudson, May 7, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Kazian

    Python Equivalent to Java Interfaces?

    Brian Kazian, Apr 9, 2005, in forum: Python
    Replies:
    4
    Views:
    698
    Michele Simionato
    Apr 9, 2005
  2. Fernando
    Replies:
    1
    Views:
    394
  3. James Harris

    Python music interfaces

    James Harris, Nov 10, 2005, in forum: Python
    Replies:
    2
    Views:
    391
  4. Replies:
    43
    Views:
    908
    bruno at modulix
    Apr 24, 2006
  5. Jonathan Daugherty

    Re: Missing interfaces in Python...

    Jonathan Daugherty, Apr 17, 2006, in forum: Python
    Replies:
    5
    Views:
    273
    Serge Orlov
    Apr 17, 2006
Loading...

Share This Page