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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:09:02+00:00 2026-06-05T08:09:02+00:00

How to access myvar from child in this code example: class Parent(): def __init__(self):

  • 0

How to access “myvar” from “child” in this code example:

class Parent():
    def __init__(self):
        self.myvar = 1

class Child(Parent):
    def __init__(self):
        Parent.__init__(self)

        # this won't work
        Parent.myvar

child = Child()
  • 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-05T08:09:03+00:00Added an answer on June 5, 2026 at 8:09 am

    Parent is a class – blue print not an instance of it,
    in OOPS to access attributes of an object it requires instance of the same,
    Here self/child is instance while Parent/Child are classes…

    see the answer below, may clarify your doubts.

    class Parent():
        def __init__(self):
            self.myvar = 1
    
    class Child(Parent):
        def __init__(self):
            Parent.__init__(self)
    
            # here you can access myvar like below.
            print self.myvar
    
    child = Child()
    print child.myvar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this: class SomeObject: #code to access parents MyVar class MyClass:
I am using this example I found to learn how to load class files
How do I do this? Inside the parent swf myVar value is set by
I have the following code $('#first').click(function() { myVar = $(this).next().val(); }); $('#second').blur(function() { console.log(myVar);
ms-access is connecting to a local mysql database the following code returns an error:
Using Access 2003 I want to get a table value from the two databases
I can access my variable stored in a backing bean from my JSF2 page,
I got hints from http://www.dougscripts.com/itunes/ to come up with the following code. But it
Ho can I access and change the value of var from outside the function?
I'm trying to write a simple class: class tempClass { private $myvar = null;

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.