Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 10th, 2005, 09:35 PM
Daniel Schüle
Guest
 
Posts: n/a
Default 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()
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)
***************************************

[color=blue][color=green][color=darkred]
>>>p = wavePlayer.wavePlayer()[/color][/color][/color]
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
[color=blue][color=green][color=darkred]
>>> class base1:[/color][/color][/color]
.... def __init__(self):
.... self.x = []
.... print "base1"
.... def __del__(self):
.... print "~base1"
....[color=blue][color=green][color=darkred]
>>> class base2:[/color][/color][/color]
.... def __init__(self, a, b):
.... self.x = a * b
.... print "base2"
.... def __del__(self):
.... print "~base2"
....[color=blue][color=green][color=darkred]
>>> class derived(base1, base2):[/color][/color][/color]
.... def __init__(self):
.... print "derived"
.... base1.__init__(self)
.... base2.__init__(self, 5, 7)
.... def __del__(self):
.... print "~derived"
....[color=blue][color=green][color=darkred]
>>> d = derived()[/color][/color][/color]
derived
base1
base2[color=blue][color=green][color=darkred]
>>> dir(d)[/color][/color][/color]
['__del__', '__doc__', '__init__', '__module__', 'x'][color=blue][color=green][color=darkred]
>>> d.x[/color][/color][/color]
35[color=blue][color=green][color=darkred]
>>>
>>> del d[/color][/color][/color]
~derived[color=blue][color=green][color=darkred]
>>>
>>>[/color][/color][/color]

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
  #2  
Old August 10th, 2005, 10:05 PM
wittempj@hotmail.com
Guest
 
Posts: n/a
Default Re: providing arguments to base.__init__

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

  #3  
Old August 10th, 2005, 10:05 PM
Rob Conner
Guest
 
Posts: n/a
Default Re: providing arguments to base.__init__

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

  #4  
Old August 10th, 2005, 10:15 PM
Daniel Schüle
Guest
 
Posts: n/a
Default Re: providing arguments to base.__init__

Rob Conner schrieb:[color=blue]
> seems like you are not running the correct wavePlayer. make sure you
> don't have 2 wavePlayer vars.
>[/color]

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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles