Why doesn't warp function in Python get executed when I call it?
<p>I have this simple code.</p>

<pre><code>def decor(func):
  def wrap():
    print("============")
    func()
    print("============")
  return wrap

def print_text():
  print("Hello world!")

decor(print_text())
</code></pre>

<p>Why does this only print "Hello world!" and not the two wrappers? </p>

<p>Here you are evaluating <code>print_text</code> (thus printing "Hello World!"), and passing the result to <code>decor</code>:</p>

<pre><code>decor(print_text())
</code></pre>

<p>Here we are passing <code>print_text</code> to <code>decor</code>, and calling the resulting function which it returns, which is <code>wrap</code>::</p>

<pre><code>decor(print_text)()
</code></pre>

<p>Notice that the first case will NOT call the function returned from <code>decor</code>. Try to call it and see what happens:</p>

<pre><code>decor(print_text())()
</code></pre>

<blockquote>
  <p>TypeError: 'NoneType' object is not callable</p>
</blockquote>

<p>because <code>func</code> is now <code>None</code>.</p>

python wrap