title: Using Loops to decorate multiple imported functions in Python
body: <p>I am new to Python and decorators, so apologies if this seems to be a trivial question.</p>
  
  <p>I am trying to apply decorators to multiple imported functions using a loop in Python as shown below</p>
  
  <pre><code>from random import random, randint, choice
  
  def our_decorator(func):
      def function_wrapper(*args, **kwargs):
          print("Before calling " + func.__name__)
          res = func(*args, **kwargs)
          print(res)
          print("After calling " + func.__name__)
      return function_wrapper
  
  for f in [random, randint, choice]:
      f = our_decorator(f)
  
  random()
  randint(3, 8)
  choice([4, 5, 6])
  </code></pre>
  
  <p>Ideally, I expect the output to be in this form :</p>
  
  <pre><code>Before calling random
  &lt;random_value&gt;
  After calling random
  Before calling randint
  &lt;random_integer&gt;
  After calling randint
  Before calling choice
  &lt;random_choice&gt;
  After calling choice
  </code></pre>
  
  <p>But, I am only getting the result of the choice function as the output.</p>
  
  <pre><code>&lt;random_choice among 4,5 6&gt;
  </code></pre>
  
  <p>The decorator has not been applied to any of the functions and it also looks like the random() and the randint(3,8) calls are not getting executed.</p>
  
  <p>I  would like to know, what is going wrong here and what can be done to decorate multiple imported functions using loops?</p>
  
  <p>Thanks for the help</p>