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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:06:23+00:00 2026-05-14T15:06:23+00:00

Need to create a class that will do all things as the merge function.

  • 0

Need to create a class that will do all things as the “merge” function. In class i will change, process and add new arguments.

def merge(*arg, **kwarg): # get decorator args & kwargs
    def func(f):
        def tmp(*args, **kwargs): # get function args & kwargs    
            kwargs.update(kwarg) # merge two dictionaries
            return f(*args, **kwargs) # return merged data
        return tmp
    return func

Usage:

@other_decorator # return *args and **kwarg
@merge(list=['one','two','three']) # need to merge with @other_decorator
def test(*a, **k): # get merged args and kwargs
    print 'args:', a
    print 'kwargs:', k
  • 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-14T15:06:23+00:00Added an answer on May 14, 2026 at 3:06 pm

    I’m not sure I quite get what you’re asking. Your implementation works fine, and you won’t get around having two levels of indirection if you want to create a parametrized decorator of any kind.

    To make merge a class you could do this

    class Merge(object):
        def __init__(self, **extra_kws):
            self.extra_kws = extra_kws
        def __call__(self, function):
            def _wrapper(*args, **kws):
                kws.update(self.extra_kws)
                return function(*args, **kws)
            return _wrapper
    

    Then you can do this:

    @Merge(foo='bar')
    def test(*args, **kws):
        print *args
        print **kws
    

    But you said you want to add change and process new arguments. So presumably you want the decorator itself to be live so you can do:

    test.extra_kws['sun'] = 'dock'
    

    After the decorator has been applied. In that case you probably don’t want merge to be a class, but you want it to generate a class, so that test is replaced by the modifiable instance:

    def merge(**extra_kws):
        class _Merge(object):
            def __init__(self, function):
                self.extra_kws = extra_kws
                self.function = function
            def __call__(self, *args, **kws):
                kws.update(self.extra_kws)
                return self.function(*args, **kws)
        return _Merge
    
    @merge(foo='bar')
    def test(*args, **kws):
        print 'args:', args
        print 'kws:', kws
    
    test(sun='dock')
    test.extra_kws['trog'] = 'cube'
    test(sun='dock')
    

    This then allows you to change the keywords on a particular decorated function later.

    You could also do the same thing with function arguments without classes:

    def merge(**extra_kws):
        def _decorator(function):
            def _wrapper(*args, **kws):
                kws.update(_wrapper.extra_kws)
                return function(*args, **kws)
            _wrapper.extra_kws = extra_kws
            return _wrapper
        return _decorator
    
    @merge(foo='bar')
    def test(*args, **kws):
        print 'kws:', kws
    
    test(sun='dock')
    test.extra_kws['trog'] = 'cube'
    test(sun='dock')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 495k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could try adding an invisible character to the beginning… May 16, 2026 at 11:24 am
  • Editorial Team
    Editorial Team added an answer You could use a PHP SOAP Extension to invoke a… May 16, 2026 at 11:24 am
  • Editorial Team
    Editorial Team added an answer In Windows you can use CryptProtectData function to encrypt your… May 16, 2026 at 11:24 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

So right now i need to create and implement an extension of the Python
I have a master-detail relationship between 2 classes. The master class will contain a
$('h2').each(function() { $('UL.chapters_list').append($('<li/>', {text: $(this).text()})) }); This code grabs all of the <H2> tags
I am maintaining a data warehouse with multiple sources of data about a class
I would like to write an object generator for a templated RAII class --
I was working on an abstract class to save on some code for a
I am currently replacing some home baked task functionality with a new implementation using
I have a navigation menu that has submenus slide down on hover. The menu
In the class fooBase there is SomeProperty . In the class barBase , I
In my job project I have recently been asked to generate POM files via

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.