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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:56:42+00:00 2026-05-14T16:56:42+00:00

This is not the result I expect to see: class A(dict): def __init__(self, *args,

  • 0

This is not the result I expect to see:

class A(dict):
    def __init__(self, *args, **kwargs):
        self['args'] = args
        self['kwargs'] = kwargs

class B(A):
    def __init__(self, *args, **kwargs):
        super(B, self).__init__(args, kwargs)

print 'Instance A:', A('monkey', banana=True)
#Instance A: {'args': ('monkey',), 'kwargs': {'banana': True}}

print 'Instance B:', B('monkey', banana=True)
#Instance B: {'args': (('monkey',), {'banana': True}), 'kwargs': {}}

I’m just trying to get classes A and B to have consistent values set. I’m not sure why the kwargs are being inserted into the args, but I’m to presume I am either calling __init__() wrong from the subclass or I’m trying to do something that you just can’t do.

Any tips?

  • 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-14T16:56:42+00:00Added an answer on May 14, 2026 at 4:56 pm

    Try this instead:

    super(B, self).__init__(*args, **kwargs)
    

    Since the init function for A is expecting actual args/kwargs (and not just two arguments), you have to actually pass it the unpacked versions of args/kwargs so that they’ll be repacked properly.

    Otherwise, the already-packed list of args and dict of kwargs gets re-packed as just an args list with two elements, and an empty kwargs dict, due to the fact that you’re passing a list and a dict, instead of actual unnamed and named parameters.

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

Sidebar

Related Questions

Why does this: (new[]{1,2,3}).Cast<decimal>(); result in an InvalidCastException: Specified cast is not valid.
This might be a super easy answer, since I'm sure it's not uncommon. I
I am trying to understand this behavior. It's definitely not what I expect. I
I want to print a simple statement print (1=1), i expect the result to
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
Surely there is a better way to do this? results = [] if not
Sorry for this not being a real question, but Sometime back i remember seeing
I ask this not to start anything negative. Rather, after looking at ASP.NET MVC
why is this not ok? aContract = function(){}; aContract.prototype = { someFunction: function() {
Why does this not work? Do I not understand delegate covariance correctly? public delegate

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.