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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:24:06+00:00 2026-06-17T16:24:06+00:00

Sorry if I did not explain myself clearly. I would like to create a

  • 0

Sorry if I did not explain myself clearly.
I would like to create a wrapper to call pre-defined functions with different number of inputs. Of course, I can create an individual wrapper for each function, but I am wondering if there is a way to create a generic wrapper for all cases.

The functions that should be called are named ‘fun1’ and ‘fun2’ with different number of inputs. I need to create a wrapper ‘fun_wrap(func_name, uncertain amount of inputs)’, which only needs the function name to be called and its associated amount of inputs.

One more thing, I need to change the input names by adding ‘_in’ and make them global variables first. Below is my broken code. Thanks for any suggestions!

def fun1(a,b):
    return a+b

def fun2(a,b,c):
    return a*b/c

def set_globals(**kwargs):
    for argname in kwargs:
        globals()['%s_in' % argname] = kwargs[argname]

def fun_wrap(func_name, uncertain amount of inputs):
    ffunc_name(set_globals(uncertain amount of inputs))

In this way, if I can call final_fun with arguments like:

fun_wrap(fun1,a,b)
fun_wrap(fun2,a,b)

UPDATE

I tried to use *arg, but failed…

def fun1(a,b):
    return a+b

def fun2(a,b,c):
    return a*b/c

def set_globals(**kwargs):
    for argname in kwargs:
        globals()['%s_in' % argname] = kwargs[argname]

def fun_wrap(func_name, *arg):
    func_name(set_globals(*arg))

fun_wrap(fun2,a=1,b=2,c=3)

got error:

Traceback (most recent call last):
  File "D:\Dropbox\AppPest\rice\try.py", line 19, in <module>
    fun_wrap(fun2,a=1,b=2,c=3)
TypeError: fun_wrap() got an unexpected keyword argument 'a'
  • 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-17T16:24:07+00:00Added an answer on June 17, 2026 at 4:24 pm
    def fun1(a,b):
        return a + b
    
    def fun2(a,b,c):
        return a * b / c
    
    def set_globals(**kwargs):
        for argname in kwargs:
            globals()['%s_in' % argname] = kwargs[argname]
    
    def fun_wrap(func, **kwargs):
        set_globals(**kwargs)       # made the call to set_globals before calling your function
        return func(**kwargs)       # return the value returned by the functions called
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry folks but I asked a question earlier and perhaps did not explain myself
Sorry, I'm sure making a silly mistake, but did not work out. I'm compiling
Sorry for the bad title - I simply do not know what to call
Sorry if the title made no sense but I did not know how to
Sorry about the lame question but reading MSDN did not make that clear to
sorry, I did not find something useful when searching google. Very basic question, mainly
I am sorry if this question is double somewhere, I've searched but did not
Sorry for asking very basic question. I would like to set OR condition in
I did not find the answer so i ask the question... Sorry to bother.
Sorry if i posted this here wrong. But i sort of did not know

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.