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

  • SEARCH
  • Home
  • 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 8017719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:55:29+00:00 2026-06-04T20:55:29+00:00

First I’ve learned what Python decorators are and how they work. And I’d like

  • 0

First I’ve learned what Python decorators are and how they work. And I’d like it to do something like this:

def age_over_18(go_enjoy_yourself):

    def go_home_and_rethink_your_life():

        return 'So you should go home and rethink your life.'

    return go_enjoy_yourself if age_stored_somewhere > 18 else go_home_and_rethink_your_life

@age_over_18
def some_porn_things():

    return '-Beep-'

But I found out that decorators are executed when the function is first read by Python, that means this function will actually do nothing.

I know I can write something like:

def some_porn_things():

    if age_stored_somewhere > 18:
        ...
    else:
        ...

But I just think decorators are graceful and easy to understand, so the question is:

Can I delay a decorator to happen until I call the function?

  • 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-06-04T20:55:31+00:00Added an answer on June 4, 2026 at 8:55 pm

    The trick is just to ensure that the check happens in your inner function, not the outer one. In your case:

    def age_over_18(go_enjoy_yourself):
        def are_you_over_18():
            if age > 18:
                return go_enjoy_yourself()
            else:
                return 'So you should go home and rethink your life.'
    
        return are_you_over_18
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all there is probably a question like this already but i couldn't
First, my question might sound like a duplicate, but I have been going through
First of all this is how the script works: jsfiddle So, I want to
first I used onDestroy() method as below to make something when my app is
First time posting here, will try to be succinct. This is a classic 'can't
First I will ask users How many names you want to enter?. Once they
First of all, I am sorry if this question doesn't belong to SO since
First, this has never worked before, so it is not specifically related to VS
First of all, I have used ALL of the suggested methods in this SO
First of all, I'm sorry about the feedback-nature of this question. I'm trying to

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.