title: How to tell if the last function was called in a class: Python
body: <p>I have a Python class similar to the following:</p>
  
  <pre><code>class BuildSentence(object):
  
      def __init__(self, intro):
          self.sentence = intro
  
      def name(self, na):
          self.sentence += "; my name is %s" % (na)
  
      def surname(self, su):
          self.sentence += "; my surname is %s" % (su)
  
      def age(self, ag):
          self.sentence += "; I am %d years old" % (ag)
  
      def final_sentence(self):
          self.sentence += "."
          return do_something_with(self.sentence)
  </code></pre>
  
  <p>I want the <code>final_sentence'</code> function called automatically <strong>only</strong> when all the required functions are finished.  The 'final_sentence' function does not necessarily return a string, it may be an integer or list.  I am not sure if it is possible to identify the last function called?</p>
  
  <p>For instance:</p>
  
  <pre><code>s = BuildSentence("Hello")
  answer = s.name("Foo").age(40)
  </code></pre>
  
  <p>Should 'do_something_with':</p>
  
  <pre><code>Hello; my is Foo; I am 40 years old.
  </code></pre>