Help needed in OOP-Python

Toufeeq Hussain toufeeqh at gmail.com
Wed Oct 5 01:34:23 EDT 2005


Hello gurus,

Python n00b here trying to learn some OOP-Python.Here's my problem.

I have 3 modules which have class declarations in them and which implement
multiple inheritance.

Module1
--------
class OptionClass:
def __init__ (self,name,ORSpecNumber,AltToItselfStart,AltToItselfEnd) :
self.Name = name
self.ORSpecNumber = ORSpecNumber
self.AltToItselfStart = AltToItselfStart
self.AltToItselfEnd = AltToItselfEnd
class Warning:
def __init__(self,Warn_number,Warn_name,Warn_type,Warn_text) :
self.Warn_name = Warn_name
self.Warn_number = Warn_number
self.Warn_type = Warn_type
self.Warn_text = Warn_text
def Fire(self) :
common_subs.write_to_out_file('FOO_OUT',self.Warn_text)

class characterestic:
def __init__(self,char_name,char_type,char_value) :
self.Char_name = char_name
self.Char_type = char_type
self.Char_value = char_value

In Module2 I have a class which derives from OptionClass of Module1.

Module2
------------
import Module1

class Option1(Module1.OptionClass):
def __init__(self) :
Module1.OptionClass.__init__('Blah Blah','OR0001','0000','0000')
option_char = Module1.characterestic
('strOperationalWeightsTemplate','int',1000)

Module3 has a Class which Derives from the Class defined in Module2.

Module3
------------
import Module1
import Module2

class Option1_Rule1(declaration.Option1):
def __init__(self) :
Module2.Option1.__init__(self)
Option1_warning = Module1.Warning(1,'This is a warning
name','Compatibility','Blah Blah,warning text which gets printed')
def Option1_constraint(self):
if isinstance(self,Module2.Option1):
print 'condition satisfied'
self.FOO_warning.Fire()
else :
pass

Finally I have a simple script which does the instantiation of the Class
defined in Module3.

Script
-----
import Module3

Test_Case = Module3.Option1_Rule1()
Test_Case.Option1_constraint()

Problem is when I run the above script it throws out the following error.

Traceback (most recent call last):
File "E:\PyPBM\PyPBM\test_case.py", line 7, in ?
TH = constraint.Option1_Rule1()
File "E:\PyPBM\PyPBM\constraint.py", line 13, in __init__
declaration.Option1.__init__(self)
TypeError: __init__() takes no arguments (1 given)

in the above errors:
test_case is the above script.
constraint => Module3
declaration => Module2
superclass => Module1

Help required.

Thanks,
Toufeeq
--
Get Firefox:http://www.mozilla.org/products/firefox/
The fastest, safest and best Browser !!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051005/9d26f563/attachment.html>


More information about the Python-list mailing list