providing arguments to base.__init__

  • Thread starter =?ISO-8859-15?Q?Daniel_Sch=FCle?=
  • Start date
?

=?ISO-8859-15?Q?Daniel_Sch=FCle?=

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)
***************************************

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
.... def __init__(self):
.... self.x = []
.... print "base1"
.... def __del__(self):
.... print "~base1"
........ def __init__(self, a, b):
.... self.x = a * b
.... print "base2"
.... def __del__(self):
.... print "~base2"
........ def __init__(self):
.... print "derived"
.... base1.__init__(self)
.... base2.__init__(self, 5, 7)
.... def __del__(self):
.... print "~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
 
W

wittempj

I only have an answer to the last one: you do not call the
'destructors' of the base classes, so they are not executed.
 
R

Rob Conner

seems like you are not running the correct wavePlayer. make sure you
don't have 2 wavePlayer vars.
 
?

=?ISO-8859-1?Q?Daniel_Sch=FCle?=

Rob said:
seems like you are not running the correct wavePlayer. make sure you
don't have 2 wavePlayer vars.

I am not sure I understand right
wavePlayer.py is a module I wrote myself and placed
to site-packages so there is no other wavePlayer module
I put a class wavePlayer into it and after

import wavePlayer
p = wavePlayer.wavePlayer()

I got this error

Regards, Daniel
 

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,879
Messages
2,569,939
Members
46,232
Latest member
DeniseMcVi

Latest Threads

Top