LearnFrenzy
Sign in Take a free test

Decorators · Predict the Output · Question 2

__name__ with and without wraps Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What is the output of the following Python program?

main.py
from functools import wraps

def d1(f):
    def wrapper(*a): return f(*a)
    return wrapper

def d2(f):
    @wraps(f)
    def wrapper(*a): return f(*a)
    return wrapper

@d1
def alpha(): pass

@d2
def beta(): pass

print(alpha.__name__, beta.__name__)
  • A alpha beta
  • B wrapper wrapper
  • C wrapper beta Correct
  • D alpha wrapper
Correct Answer: Option C

Without wraps the decorated name reports the wrapper's metadata.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links