Why does Python call both functions?
<p>I have some problems to understand what happens here.</p>

<p>This is my source:</p>

<pre><code>class Calc():

    def __init__(self,Ideal,Limit,Value,Debug=None):

        self.Ideal = Ideal
        self.Limit = Limit
        self.Value = Value
        self.Debug = Debug
        self.Grade = self.GetGrade()
        self.LenGrade = self.GetLenGrade()

    def GetGrade(self):
        if self.Debug:
            print('calling GetGrade')
        return Grade

    def GetLenGrade(self):
        if self.Debug:
            print('calling GetLenGrade')
        return Grade
</code></pre>

<p>When calling it with</p>

<pre><code>GradeMinLen += Calc(TargetLen, LimitMinLen, Length ,Debug=1).LenGrade
</code></pre>

<p>I get always the output</p>

<pre><code>calling GetGrade    
calling GetLenGrade
</code></pre>

<p>Why is python calling <code>GetGrade</code>?</p>

<p>You create an instance of <code>Calc()</code>, and whenever you do that, <code>Calc.__init__()</code> is called for that new instance.</p>

<p>Your <code>Calc.__init__()</code> method calls both <code>self.GetGrade()</code> and <code>self.GetLenGrade()</code>:</p>

<pre><code>self.Grade = self.GetGrade()
self.LenGrade = self.GetLenGrade()
</code></pre>

<p>It doesn't matter here that <em>after</em> you created the instance you only access the <code>LenGrade</code> attribute; the above two lines in <code>__init__</code> do not store method references, they store the <em>results</em> of the method calls. The <code>Calc(...).LenGrade</code> then returns one of those results; the other result is <em>also</em> there however.</p>

python