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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:04:24+00:00 2026-06-04T19:04:24+00:00

Imagine I have a class A class A(object): def __init__(self, x, y) self.x =

  • 0

Imagine I have a class A

class A(object):
    def __init__(self, x, y)
        self.x = x
        self.y = y

and then I define a class B that is initialized by A (rather than take A as its base) and other parameters

class B(object):
    def __init__(self, a):
        if isinstance(a, A):
            self.a = a

The question is, suppose A has a gigantic amount of variables defined and shall be referred to in B frequently, is it possible to make B aware of those variables in A, so that in B I can do

self.x 

rather than

self.a.x

?

I am aware this automatic inheritable of variables is kinda dangerous and even could be destructive, but typing many extra self.a.x looks a little clunky. Having the option to turn on this inheritance temporarily or in small snippets of code should be useful.

EDIT

__dict__ brings up essentially everything, including methods and functions, possible to keep only numerical variables?

  • 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-04T19:04:27+00:00Added an answer on June 4, 2026 at 7:04 pm

    You can write:

    class B(object):
        def __getattr__(self, attr):
            if hasattr(self.a, attr):
                return getattr(self.a, attr)
            else:
                return object.__getattribute__(self, attr)
    

    Whenever you access an attribute of B, it will check if a has that attribute. If so, it’ll return that instead. If not, it will lookup the attribute in B itself.

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

Sidebar

Related Questions

Imagine that I have a nice Deck class, in the best OO fashion. It
I want to convert a string to a class name. Imagine that I have
Say I have models: class Animal(models.Model): type = models.CharField(max_length=255) class Dog(Animal): def make_sound(self): print
Assume that I have a particular class of object that defines a class method
Using the Newtonsoft.Json library, imagine I have got public class Test { public Object
Ok, let's imagine I have an object like this: public class User { public
Imagine I have a class Window with a member function show which causes the
Imagine I have a C++ class Foo and a class Bar which has to
Imagine I have an entity: public class MyObject { public string Name { get;
Imagine you have an entity that has some relations with other entities and you

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.