providing arguments to base.__init__

Daniel Schüle uval at rz.uni-karlsruhe.de
Wed Aug 10 16:17:54 EDT 2005


Hello Ng,

I was playing around with pymedia module
and I succeeded when I used complementation
instead of inheritance .. but then I was
forced to wrap simple methods of sound.Output
like pause/unpause/stop. It works, but
seems to me unnecessary .. and I would like
to grasp why the code below doesn't work

***************************************
import threading, wave, sys,
import pymedia.audio.sound as sound, tkFileDialog

class wavePlayer(threading.Thread, sound.Output):
  def __init__(self, filename = None):
   if filename == None:
    filename = tkFileDialog.askopenfilename()
   try:
    self.wav = wave.open(filename)
   except:
    print "something went wrong"
    sys.exit(1)
   freq, nchannels, format = self.wav.getframerate(),
self.wav.getnchannels(), sound.AFMT_S16_LE
   sound.Output.__init__(self, freq, nchannels, format)
   threading.Thread.__init__(self)
***************************************


 >>>p = wavePlayer.wavePlayer()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: Output() takes at least 3 arguments (0 given)


can somebody explain why this happens?
I tried to construct more simple example
but there it works fine, here is it

 >>> class base1:
...     def __init__(self):
...             self.x = []
...             print "base1"
...     def __del__(self):
...             print "~base1"
...
 >>> class base2:
...     def __init__(self, a, b):
...             self.x = a * b
...             print "base2"
...     def __del__(self):
...             print "~base2"
...
 >>> class derived(base1, base2):
...     def __init__(self):
...             print "derived"
...             base1.__init__(self)
...             base2.__init__(self, 5, 7)
...     def __del__(self):
...             print "~derived"
...
 >>> d = derived()
derived
base1
base2
 >>> dir(d)
['__del__', '__doc__', '__init__', '__module__', 'x']
 >>> d.x
35
 >>>
 >>> del d
~derived
 >>>
 >>>

base2.__init__ is called in the same way
sound.Output.__init__ is called
both get multiple arguments

one more curiosity, why doesn't del d, call destructors
of base classes?

Thanks for you answears

--
Daniel



More information about the Python-list mailing list