title: Does python have macros?
body: <p>I am wondering whether python has macros like C/C++, that will insert the code at the caller site instead of making a function call. One use case I have in mind is as follows</p>
  
  <pre><code># In lib.py
  def get_current_dir():
      return os.path.dirname(os.path.realpath(__file__))
  
  # In app.py
  current_dir = get_current_dir()
  </code></pre>
  
  <p>This does not work unless <code>get_current_dir</code> is a macro, i.e. it replace the <code>get_current_dir</code> call with the <code>os.path.dirname(os.path.realpath(__file__))</code> inside the <code>app.py</code>. Because otherwise the returned directory will be the one <code>lib.py</code> lives in, which is not necessarily the same as <code>app.py</code> lives in.</p>