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

The Archive Base Latest Questions

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

I have a Python class with many methods with signature: def select_xxx(self, arg1 ,

  • 0

I have a Python class with many methods with signature:

def select_xxx(self, arg1 , arg2 , .. argn, intersect = False)

I.e. the methods have a varying (1-3) number of positional arguments, and an optional argument intersect with default value False. I would like to decorate all of these methods with a decorater which will insepect the value of the intersect parameter and take different actions accordingly. My current approach is something like this:

def select_decorator(select_method):

  def select_wrapper( self , *args, intersect = False , **kwargs)
     if intersect:
        # Special init code for intersect == True
        select_method( self , *args , **kwargs)
     else:
        # Normal call path for intersect == False 
        select_method( self , *args , **kwargs)

  return select_wrapper  

@select_decorator
select_xxx( self , arg1 , arg2 , intersect = False)

But getting the optional argument intersect into the *args and **kwargs mix inside the decorator is currently no joy. I could sacrifice the **kwargs functionality if that makes the problem easier to solve. Any suggestions?

Joakim

  • 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-30T20:55:10+00:00Added an answer on May 30, 2026 at 8:55 pm

    I am assuming that intersect will always be passed as keyword argument. In which case you could simply do this inside you decorator

    def select_decorator(select_method):
    
      def select_wrapper( self , *args, **kwargs):
         intersect = kwargs.has_key('intersect') and kwargs['intersect']
         if intersect:
            # Special init code for intersect == True
            select_method( self , *args , **kwargs)
         else:
            # Normal call path for intersect == False 
            select_method( self , *args , **kwargs)
      return select_wrapper  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of many Python objects like this: class RangeClass(object): def __init__(self,address,size):
I have a python class with many methods(): Method1() Method2() ........... ........... MethodN() All
okay code: #!/usr/bin/python import wx import sys class XPinst(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self,
I have a Python class full of static methods. What are the advantages and
I have a python module that defines a number of classes: class A(object): def
I have written a class in python that implements __str__(self) but when I use
Not many are aware of this feature, but Python's functions (and methods) can have
Does C# have anything like Python's __getattr__ ? I have a class with many
I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model):
I have a python class which reads a config file using ConfigParser: Config file:

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.