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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:12:46+00:00 2026-05-23T19:12:46+00:00

I need some help with figuring out Pythons *args and **kwargs . It’s simple

  • 0

I need some help with figuring out Pythons *args and **kwargs. It’s simple but I haven’t entire wrapped my head around them. Here’s one of scenarios that’s bewildering to me.

I have two functions mainfunc and wrapperfunc (which is a wrapper function for the main function). It looks like this.

def mainfunc(fname=None, lname=None):
    print 'Firstname: ' + fname
    print 'Lastname: ' + lname

def wrapperfunc(uname, *args):
    print uname
    mainfunc(*args)

I can call wrapperfunc like this:

wrapperfunc('j.doe', 'john', 'doe')

In this method, all three parameters are positional. Since j.doe comes into uname, the other two params can be accessed by *args

..but is it possible to pass some of the params to wrapperfunc from a dict so that I can still access uname inside wrapperfunc directly and then pass the remaining positional parameters to the mainfunc. Something like the following snippet:

params = {'uname':'j.doe'}
wrapperfunc(**params, 'john', 'doe')

I want to access the named parameters directly inside wrapperfunc but pass all the positional parameters to mainfunc.

  • 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-23T19:12:47+00:00Added an answer on May 23, 2026 at 7:12 pm

    Keyword arguments must come after position arguments in Python.

    params = {'uname':'j.doe'}
    wrapperfunc('john', 'doe', **params)
    

    will pass the keyword arguments after the two positional arguments,

    If you want to look at an argument, but otherwise do the call normally, do:

    def wrapper(*args, **kwargs):
        print kwargs["uname"]
        return mainfunc(*args, **kwargs)
    

    You can generalize this to work on any function you want as a decorator.

    def wrapper(f):
        def wrapped(*args, **kwargs):
            print kwargs["uname"]
            return mainfunc(*args, **kwargs)
        return wrapped
    
    @wrapper
    def foo(uname="Test"):
        return uname + "bar"
    
    # the @decorator is equivalent to `foo = wrapper(foo)`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some php help in figuring out how use this array I created, but
I need some help figuring out what I'm doing wrong here. I am trying
I need some help figuring out and SQL Statement. I know what I want
I'm looking to implement the Shunting-yard Algorithm , but I need some help figuring
I need some help figuring out why the following scenario does not work. I'm
I need some help from the shell-script gurus out there. I have a .txt
I'm currently working on my own PHP Framework, and I need some help figuring
I have a 5 byte data element and I need some help in figuring
I need some help regarding algorithm for randomness. So Problem is. There are 50
I need some help calculating Pi. I am trying to write a python program

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.