469,610 Members | 2,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

providing arguments to base.__init__

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()
self.wav = wave.open(filename)
print "something went wrong"
freq, nchannels, format = self.wav.getframerate(),
self.wav.getnchannels(), sound.AFMT_S16_LE
sound.Output.__init__(self, freq, nchannels, format)

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

Aug 10 '05 #1
3 1279
I only have an answer to the last one: you do not call the
'destructors' of the base classes, so they are not executed.

Aug 10 '05 #2
seems like you are not running the correct wavePlayer. make sure you
don't have 2 wavePlayer vars.

Aug 10 '05 #3
Rob Conner schrieb:
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
Aug 10 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Gabriel Genellina | last post: by
1 post views Thread by Greg Lindstrom | last post: by
3 posts views Thread by Peter Olsen | last post: by
7 posts views Thread by Kent Johnson | last post: by
4 posts views Thread by Steven D'Aprano | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.