Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 559661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:15:40+00:00 2026-05-13T12:15:40+00:00

Why arn’t the following two scripts equivalent? (Taken from another question: Understanding Python Decorators

  • 0

Why arn’t the following two scripts equivalent?

(Taken from another question: Understanding Python Decorators)

def makebold(fn):
    def wrapped():
        return "<b>" + fn() + "</b>"
    return wrapped

def makeitalic(fn):
    def wrapped():
        return "<i>" + fn() + "</i>"
    return wrapped

@makebold
@makeitalic
def hello():
    return "hello world"

print hello() ## returns <b><i>hello world</i></b>

and with a decorated decorator:

def makebold(fn):
    def wrapped():
        return "<b>" + fn() + "</b>"
    return wrapped

@makebold
def makeitalic(fn):
    def wrapped():
        return "<i>" + fn() + "</i>"
    return wrapped

@makeitalic
def hello():
    return "hello world"

print hello() ## TypeError: wrapped() takes no arguments (1 given)

Why do I want to know? I’ve written a retry decorator to catch MySQLdb exceptions – if the exception is transient (e.g. Timeout) it will re-call the function after sleeping a bit.

I’ve also got a modifies_db decorator which takes care of some cache-related housekeeping. modifies_db is decorated with retry, so I assumed that all functions decorated with modifies_db would also retry implicitly. Where did I go wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:15:40+00:00Added an answer on May 13, 2026 at 12:15 pm

    The problem with the second example is that

    @makebold
    def makeitalic(fn):
        def wrapped():
            return "<i>" + fn() + "</i>"
        return wrapped
    

    is trying to decorate makeitalic, the decorator, and not wrapped, the function it returns.

    You can do what I think you intend with something like this:

    def makeitalic(fn):
        @makebold
        def wrapped():
            return "<i>" + fn() + "</i>"
        return wrapped
    

    Here makeitalic uses makebold to decorate wrapped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this xml example: <templateitem itemid=5> <templateitemdata>%ARN%</templateitemdata> </templateitem> <templateitem itemid=6> <templateitemdata></templateitemdata> </templateitem> I am
I am trying to block hotlinking of my Cloudfront files from specific domains. Through
I'm using the following code to display a 'previous posts' link on my Wordpress
I can't seem to execute the ssh command from any of the PHP functions
I'm having some trouble with Python's raw_input command (Python2.6), For some reason, the raw_input
I'm developing a web application and I currently have the following ACL assigned to
Im using jQuery so that choosing an option from a select list horizontally scrolls
I am sending out emails from rails, in the emails are images. Those images
I'm not too sure how to ask this question. I need to store a
As we know in C++ we have class iostream, which is inherited from istream(basic_istream)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.