Python Forum
the order of running code in a decorator function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
the order of running code in a decorator function
#1
hi
in below code:
# from:https://python.coderz.ir/lessons/l14-recursive-  \
# functions-and-memoization-in-python.html 

def logger(func):
     print('Decorator is created!')
     def func_wrapper(number):
         print(f'New factorial call with parameter: {number}')
         result = func(number)
         print (f'factorial({number}) ==> {result}')
         return result
     return func_wrapper

@logger
def factorial(n):
    if n <= 1:
         return 1
    else:
         return n            #* factorial(n - 1)

def test():
     print("it is a test")

if __name__=="__main__" :
    test() 
    print(f"factoril(5) is : {factorial(5)}")
I ran and debugged the above code in idle.
the order of running lines was: 4,13,14,13,5,6,11,14,20,23,24,21,25,7,8,15,18,9,10 .
the above code is a decorator function. why the order of running lines is as above line? plz, explain.
thanks
Reply


Messages In This Thread
the order of running code in a decorator function - by akbarza - Nov-09-2023, 09:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 711 Feb-14-2024, 02:57 PM
Last Post: snippsat
  super() and order of running method in class inheritance akbarza 7 828 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  writing and running code in vscode without saving it akbarza 1 430 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  Curious about decorator syntax rjdegraff42 14 2,210 May-03-2023, 01:21 PM
Last Post: rjdegraff42
  Code running many times nad not just one? korenron 4 1,398 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 3,848 Jul-01-2022, 02:51 PM
Last Post: maiya
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 1,546 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  Why is this Python code running twice? mcva 5 5,362 Feb-02-2022, 10:21 AM
Last Post: mcva
  Python keeps running the old version of the code quest 2 3,829 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime
  My python code is running very slow on millions of records shantanu97 7 2,646 Dec-28-2021, 11:02 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020