1


I have a small Python OOP program in which 2 class, Flan and Outil inherit from a superclass Part.
My problem is when I call Flan everything works perfectly, however when I call Outil the program fails silently.
The Outil instance is created, but it lacks all the attributes it doesn't share with Part.
The Outil instance isn't added to Outil.list_instance_outils, nor to Part.list_instances.

class Outil(Part):

    list_instance_outils = []    

    def __init___(self, name, part_type, nodes, elems):
        Part.__init__(self, name, part_type, nodes, elems)
        self.vect_norm = vectnorm(self.nodes[self.elems[0,1:]-1, 1:])
        self.elset = Elset(self)
        self.nset = Nset(self, refpoint=True, generate=False)
        self.SPOS = Ab_surface(self, self.elset)
        self.SNEG = Ab_surface(self, self.elset, type_surf='SNEG')
        Outil.list_instance_outils.append(self)
        Part.list_instances.append(self)

class Flan(Part):

    list_instances_flans = []    

    def __init__(self, name, part_type, nodes, elems):
        Part.__init__(self, name, part_type, nodes, elems)       
        self.vect_norm = vectnorm(self.nodes[self.elems[0,1:4]-1, 1:])
        self.elset = Elset(self)
        self.nset = Nset(self)
        self.SPOS = Ab_surface(self, self.elset)
        self.SNEG = Ab_surface(self, self.elset, type_surf='SNEG')
        Flan.list_instances_flans.append(self)        
        Part.list_instances.append(self)

Both this Classes inherit from Part :

class Part():

    list_instances = []

    def __init__(self, name, part_type, nodes, elems):
        self.name = name
        self.name_instance = self.name + '-1'
        self.part_type = part_type
        self.elems = elems
        self.nodes = nodes
        offset = np.min(self.elems[:, 1:])-1
        self.nodes[:, 0] -= offset
        self.elems[:, 1:] -= offset

I cannot stress enough that I have no error message whatsoever. What am I doing wrong here ?

4
  • 1
    Please can you indent your code properly? Commented Mar 26, 2012 at 12:07
  • OMFG ! I found my problem... in Class Outil I wrote init_ instead of init (when you see it... 3 hours..) Commented Mar 26, 2012 at 12:14
  • When you say "but it lacks all the attributes it doesn't share with Part", how do you know that? Show some test code that fails. Commented Mar 26, 2012 at 12:15
  • 2
    Good work -- the rubber duck strikes again! (en.wikipedia.org/wiki/Rubber_duck_debugging) Commented Mar 26, 2012 at 12:15

2 Answers 2

7

You wrote __init__ with three trailing underscores instead of two in Outil.

Because of this, it doesn't get called -- Part.__init__ gets called instead. That's why the class is created but it lacks the attributes beyond what are in Part.

Sign up to request clarification or add additional context in comments.

Comments

1

To solve this sort of problem, the best thing to do is to run the code through the debugger.

Get your classes into the python interpreter (import, paste, whatever you like), then call pdb: import pdb; pdb.run('Outil()'). You can now step through the code to see what is happening.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.