newbie-question: interfaces

F. GEIGER fgeiger at datec.at
Sat Apr 13 08:49:43 EDT 2002


You have to do this by yourself, i.e. there's no built-in support for this


class Abstract: # All subclasses of this have to conform to this
   def __init__(self):
      return

   def method(self):
      raise NotImplementedError # Oops, you are working with an Abstract
object or you have forgotten to override method()!


class Concrete:
   def __init__(self):
      Abstract.__init__(self)
      return

   def method(self):
      pass # Your stuff goes here
      return


a = Abstract()
a.method() # Will raise an error

c = Concrete()
c.method() # Will do, what you told it to do


Try Google to find more on this as this is frequently discussed here.

Best regards
Franz

"merman" <merman at freenet.de> schrieb im Newsbeitrag
news:3cb7f47e$0$360$9b622d9e at news.freenet.de...
> Hi,
>
> is there a way to simulate interfaces (like in java) in python?
> ... or abstract classes? (c++/ java)
>
> o-o
>
> thomas
>
>
>
>





More information about the Python-list mailing list