title: Returning different values based on where function is called from in Python
body: <p>I have two functions, each of which call a third function, but expect a slightly different thing returned back. </p>
  
  <p>All functions are in separate files. Files A and B can NOT import one another, so function A and B can not call one another. What is the best way to organize this?</p>
  
  <p>I would like to avoid duplicating the function, since most of it is identical, to stay in line with DRY principals.</p>
  
  <p>Here is some pseudo-code for what I have, and how I am thinking the program would be structured:</p>
  
  <pre><code>#FileA.py
  def functionA():
      useableData = functionC(rawData)
  </code></pre>
  
  <p>-</p>
  
  <pre><code>#FileB.py
  def functionB():
      useableData = functionC(rawData)
  </code></pre>
  
  <p>-</p>
  
  <pre><code>#FileC.py
  def functionC(rawdata):
      *Extensive processing/formatting of data*
      if C run from A:
          return useableData
  
      if C run from B:
          *A bit more processing of data*
          return useableData
  </code></pre>
  
  <p>The only solution I can think of is to pass a second variable along with <code>rawdata</code>, a string that says the name of the function it came from. But this seems inelegant to me.</p>
  
  <p>Is there an ideal way to do this? Perhaps not involving checking where the function was called from, but still allowing <code>functionC</code> to return slightly different results depending on where the data is going to be returned to. I might be able to restructure the code a bit, but all three functions need to remain in their current files.</p>