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 7520887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:08:41+00:00 2026-05-30T02:08:41+00:00

I have a decorator that currently requires each function that uses it to have

  • 0

I have a decorator that currently requires each function that uses it to have a few arguments, arg1, arg2, and arg3. It works fine.

But one of the args in particular feels extraneous in that the functions don’t really want to have it as an input, e.g. for something like

@sql_decorator
def user_records(table, user, limit):
    "sql to select records from ' + table + ' with user=%s limit %s" % (user, limit)

user and limit make sense as inputs, but table does not because the caller never has control over that. It feels extraneous.

Is there a way to do something like this:

@sql_decorator
def user_records(user, limit):
    "sql to select records from table with user=%s limit %s" % (user, limit)

and then have the decorator change the sql by finding the instance of table and changing it to the right value?

  • 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-30T02:08:43+00:00Added an answer on May 30, 2026 at 2:08 am

    If I understand you correctly, then you have something like this:

    def sql_decorator(func):
        def decorated(table, user, limit):
            ... # do stuff with table
            return func(table, user, limit)
        return decorated
    
    @sql_decorator
    def user_records(table, user, limit):
        ...
    

    If so, then this is probably what you want: No, wrong answer. See below.

    def sql_decorator(table_name):
        def the_actual_decorator(func):
            def decorated(user, limit):
                ... # do stuff with table_name
                return func(user, limit)
            return decorated
        return the_actual_decorator
    
    @sql_decorator('some_table_name')
    def user_records(user, limit):
        ...
    

    [edit] According to your comment you probably want something like this:

    def sql_decorator(func):
        def decorated(user, limit):
            table = compute_the_table_somehow(user)
            return func(table, user, limit)
        return decorated
    
    @sql_decorator
    def user_records(table, user, limit):
        "sql to select records from %s with user=%s limit %s" % (table, user, limit)
    
    data = user_records('joe', 100)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following decorator and view which works fine. Decorator def event_admin_only(func): Checks
I currently have a CSS <ul><li> dropdown menu that uses the following code. Unfortunately
I have a function that is taking an arbitrary set of arguments and then
Suppose I have written a decorator that does something very generic. For example, it
I have been trying to create a decorator that can be used with both
I'm currently building a tool that will have to match filenames against a pattern.
I have a decorator specified on a displaytag table that I need to pass
I have a very simple decorator function I use to expose functions defined in
In my DSL project I have a shape with a number of decorators that
I have heard that MbUnit comes with pretty nice test decorators which allow writing

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.