Help needed in OOP-Python

2005-10-04 Thread Toufeeq Hussain
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','','')
    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 !!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help needed in OOP-Python

2005-10-04 Thread Toufeeq Hussain
Hi Fredrik,On 10/5/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
Toufeeq Hussain wrote:> I have 3 modules which have class declarations in them and which implement> multiple inheritance.> Traceback (most recent call last):> File "E:\PyPBM\PyPBM\test_case.py", line 7, in ?
>TH = constraint.Option1_Rule1()there's no line that says "TH = constraint.Option1_Rule1()" in thecode you're posted.  looks like you didn't really post the code youtested...

my bad. :(

It's there under "script" but in a different form.


Script

-

import Module3



Test_Case = Module3.Option1_Rule1()

Test_Case.Option1_constraint()




Test_Case = "Module3.Option1_Rule1()" corresponds to "TH = constraint.Option1_Rule1()"

My coding is really really bad,that's why I changed the names to more human readable form(Module1,2.. etc).

Thanks for pointing it out,
Toufeeq
-- Get Firefox:http://www.mozilla.org/products/firefox/The fastest, safest and best Browser !!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help needed in OOP-Python

2005-10-05 Thread Toufeeq Hussain
Fredrik,

sigh!
I see the problem you mention and I agree.
Should have posted the orginal code without edits. :(
Anyway I'll try to fill in whereever required.On 10/5/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
$ python test.pycondition satisfiedTraceback (most recent call last):
  File "test.py", line 4, in ?Test_Case.Option1_constraint()  File "module3.py", line 11, in Option1_constraintself.FOO_warning.Fire()AttributeError: Option1_Rule1 instance has no attribute 'FOO_warning'
FOO_warning?  there's no FOO_warning anywhere in the code.
FOO_warning is "Option1_warning" from Module3.

And, in Module1 comment out the line:
"common_subs.write_to_out_file(
'FOO_OUT',self.Warn_text)"
:::so, after four attempts, I've found four problems, three of which was present
in your posted code, but I still haven't seen the problem you reported:Traceback (most recent call last):  File "test_case.py", line 7, in ?TH = constraint.Option1_Rule1()  File "
constraint.py", line 13, in __init__declaration.Option1.__init__(self)TypeError: __init__() takes no arguments (1 given)
But the script when given as individual commands works fine in IDLE.
While executing the script it throws that error. :( 
which, in itself, looks like you've forgotten the self argument in some initmethod somewhere (but the code you posted doesn't have that problem).

Yes,I've doubled checked this. 
if you want to post code, 1) try to reduce the problem to as little code as you
possibly can, and 2) make sure that the code you post really has the problemyou're seeing... (i.e. run it at least once before you post it)
All points noted and will follow the same.
Thanks and my sincere apologies. 

-toufeeq-- Get Firefox:http://www.mozilla.org/products/firefox/The fastest, safest and best Browser !!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help needed in OOP-Python

2005-10-05 Thread Toufeeq Hussain
Thanks Fredrik.

Went through the code to make sure "self" was used properly and one of the parent classes was missing a "self".It's fixed now.

/me kicks self

-toufeeqOn 10/5/05, Toufeeq Hussain <[EMAIL PROTECTED]> wrote:
Fredrik,

sigh!
I see the problem you mention and I agree.
Should have posted the orginal code without edits. :(
Anyway I'll try to fill in whereever required.On 10/5/05, Fredrik Lundh <
[EMAIL PROTECTED]> wrote:
$ python test.pycondition satisfiedTraceback (most recent call last):

  File "test.py", line 4, in ?Test_Case.Option1_constraint()  File "module3.py", line 11, in Option1_constraintself.FOO_warning.Fire()AttributeError: Option1_Rule1 instance has no attribute 'FOO_warning'
FOO_warning?  there's no FOO_warning anywhere in the code.
FOO_warning is "Option1_warning" from Module3.

And, in Module1 comment out the line:
"common_subs.write_to_out_file(
'FOO_OUT',self.Warn_text)"
:::so, after four attempts, I've found four problems, three of which was present
in your posted code, but I still haven't seen the problem you reported:Traceback (most recent call last):  File "test_case.py", line 7, in ?TH = constraint.Option1_Rule1()  File "
constraint.py", line 13, in __init__declaration.Option1.__init__(self)TypeError: __init__() takes no arguments (1 given)
But the script when given as individual commands works fine in IDLE.
While executing the script it throws that error. :( 
which, in itself, looks like you've forgotten the self argument in some init
method somewhere (but the code you posted doesn't have that problem).

Yes,I've doubled checked this. 
if you want to post code, 1) try to reduce the problem to as little code as you

possibly can, and 2) make sure that the code you post really has the problemyou're seeing... (i.e. run it at least once before you post it)
All points noted and will follow the same.
Thanks and my sincere apologies. 

-toufeeq-- Get Firefox:http://www.mozilla.org/products/firefox/
The fastest, safest and best Browser !!
-- Get Firefox:http://www.mozilla.org/products/firefox/The fastest, safest and best Browser !!
-- 
http://mail.python.org/mailman/listinfo/python-list