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

The Archive Base Latest Questions

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

I have several layers of function calls, passing around a common dictionary of key

  • 0

I have several layers of function calls, passing around a common dictionary of key word arguments:

def func1(**qwargs):
    func2(**qwargs)
    func3(**qwargs)

I would like to supply some default arguments in some of the subsequent function calls, something like this:

def func1(**qwargs):
    func2(arg = qwargs.get("arg", default), **qwargs)
    func3(**qwargs)

The problem with this approach is that if arg is inside qwargs, a TypeError is raised with “got multiple values for keyword argument”.

I don’t want to set qwargs[“arg”] to default, because then func3 gets this argument without warrant. I could make a copy.copy of the qwargs and set “arg” in the copy, but qwargs could have large data structures in it and I don’t want to copy them (maybe copy.copy wouldn’t, only copy.deepcopy?).

What’s the pythonic thing to do here?

  • 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-14T19:08:24+00:00Added an answer on May 14, 2026 at 7:08 pm

    Just build and use another dict for the purpose of calling func2, leaving the original alone for the later call to func3:

    def func1(**qwargs):
        d = dict(arg=default)
        d.update(qwqargs)
        func2(**d)
        func3(**qwargs)
    

    This is if you want a setting for arg in qwargs to override the default. Otherwise (if you want default to override any possible setting for arg in qwargs):

    def func1(**qwargs):
        d = dict(qwargs, arg=default)
        func2(**d)
        func3(**qwargs)
    

    since the keyword-argument to dict overrides the value in the positional argument, if any.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy application where the method calls go several layers deep: public
I have a library several layers of require down from my project, and I'd
We have several offices around the US and one in India. Our IT department
I have a solution composed of several layers: controller > service > business >
I have a complex picture . It consists of several layers. Each layer is
I have a scenario where I have several classes that extend from a common
I have an ASP.Net MVC application with a model which is several layers deep
I have a form that collects information from several models that are several layers
Does anyone have a good example for common error handling for service calls? I
I have several layers of photos, stacked on top of each other with different

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.