title: Including the current method name when printing in Python
body: <p>Often times in C programs (and using GCC) I will create a debug print macro that includes the name of the current function. That is, something like:</p>
  
  <pre><code>#define DPRINTF(fmt, ...) printf("[%s] " fmt, __FUNCTION__, ##__VA_ARGS__)
  </code></pre>
  
  <p>When used, the current function will be prepended to each print, providing more useful debug information at runtime. For example, the following code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define DPRINT(fmt, ...) printf("[%s] " fmt, __FUNCTION__, ##__VA_ARGS__)
  
  void testfunction1(){
      DPRINT("Running %d\n",1);
  }
  
  void testfunction2(){
      DPRINT("Running %d\n",2);
  }
  
  int main(void) {
      DPRINT("Running: %d\n",0);
      testfunction1();
      testfunction2();
      return 0;
  }
  </code></pre>
  
  <p>Would output:</p>
  
  <pre><code>[main] Running: 0
  [testfunction1] Running 1
  [testfunction2] Running 2
  </code></pre>
  
  <p>Can something like this be done in Python? </p>
  
  <p>I searched around a bit and found <a href="https://stackoverflow.com/questions/5067604/determine-function-name-from-within-that-function-without-using-traceback">this</a> StackOverflow question explaining how <code>inspect</code> can be used to read names from the stack. However, from what I've found Python does not support macros, so the same form as my C program cannot be used.</p>
  
  <p>Is there some mechanism by which this type of debug printing can be supported? I tried lambdas, but the "function name" in this case prints as "&lt; lambda >". </p>