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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:53:15+00:00 2026-06-10T19:53:15+00:00

class x(): def __init__(self): self.z=2 class hi(): def __init__(self): self.child=x() f=hi() print f.z I

  • 0
class x():
    def __init__(self):
        self.z=2

class hi():
    def __init__(self):
        self.child=x()

f=hi()
print f.z

I want it to print 2.

Basically I want to forward any calls to that class to another class.

  • 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-10T19:53:16+00:00Added an answer on June 10, 2026 at 7:53 pm

    The simplest approach is implementing __getattr__:

    class hi():
        def __init__(self):
            self.child=x()
    
        def __getattr__(self, attr):
            return getattr(self.child, attr)
    

    This has certain disadvantages, but it might work for your limited use case. You might want to implement __hasattr__ and __setattr__ as well.

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

Sidebar

Related Questions

class Packagings: def __init__(self): self.length=0 self.deckle=0 self.tmp=0 self.flute=[] self.gsm=[] self.t_weight=0 self.weight=0 def read_values(self): print
It's my script: class shape: def __init__(self, name): self.name = name def printMyself(self): print
Basically I have the following code: import multiprocessing import time class MyProcess(multiprocessing.Process): def __init__(self,
class Parent(): def __init__(self): self.child = Child() class Child(): def __init__(self): # get Parent
This is what I'm trying to do in Python: class BaseClass: def __init__(self): print
Consider the following code example (python 2.7): class Parent: def __init__(self, child): self.child =
What's the difference between: class Child(SomeBaseClass): def __init__(self): super(Child, self).__init__() and: class Child(SomeBaseClass): def
I have two classes: class Base(object): def __init__(self): object.__init__(self) def print_methods(self): print self.__dict__ class
So I have this: class Parent(object): def __init__(self, val): print 'enter Base init' self._set_x(val)
class Packagings: def _init_(self): self.length,self.deckle,self.tmp,self.flute,self.gsm,self.t_weight,self.weight def read_values(self): print Select Type Of Paper 1.3 Ply

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.