473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
Aug 10 '05 #1
3 1396
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1844
by: John J. Lee | last post by:
I'm trying define a class to act as a Mock "handler" object for testing urllib2.OpenerDirector. OpenerDirector (actually, my copy of it) does dir(handler.__class__) to find out what methods a...
2
2022
by: Gabriel Genellina | last post by:
Hi In the following code sample, I have: - a Worker class, which could have a lot of methods and attributes. In particular, it has a 'bar' attribute. This class can be modified as needed. - a...
14
3302
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
1
1788
by: Greg Lindstrom | last post by:
Hello- I have a base class which does the heavy lifting associated with creating, modifying, and writing record segments for an application I've developed. One of the requirements of the app is...
3
1683
by: Peter Olsen | last post by:
I want to define a class "point" as a subclass of complex. When I create an instance sample = point(<arglist>) I want "sample" to "be" a complex number, but with its real and imaginary...
8
2520
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
1
2409
by: Gerry Sutton | last post by:
Hi All! I have noticed a strange behavior when using a constant identifier to initialize an instance list variable in a base class and then trying to modifying the list in subclasses by using...
7
5229
by: Kent Johnson | last post by:
Are there any best practice guidelines for when to use super(Class, self).__init__() vs Base.__init__(self) to call a base class __init__()? The super() method only works correctly in multiple...
4
3522
by: Steven D'Aprano | last post by:
When you call a new-style class, the __new__ method is called with the user-supplied arguments, followed by the __init__ method with the same arguments. I would like to modify the arguments...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.