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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:00:30+00:00 2026-05-22T15:00:30+00:00

I am trying to access a variable from the base class. Here’s the parent

  • 0

I am trying to access a variable from the base class. Here’s the parent class:

class Parent(object):
    def __init__(self, value):
        self.some_var = value

And here’s the child class:

class Child(Parent):
    def __init__(self, value):
        super(Child, self).__init__(value)

    def doSomething(self):
        parent_var = super(Child, self).some_var

Now, if I try to run this code:

obj = Child(123)
obj.doSomething()

I get the following exception:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    obj.doSomething()
  File "test.py", line 10, in doSomething
    parent_var = super(Child, self).some_var
AttributeError: 'super' object has no attribute 'some_var'

What am I doing wrong? What is the recommended way to access variables from the base class in Python?

  • 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-22T15:00:31+00:00Added an answer on May 22, 2026 at 3:00 pm

    After the base class’s __init__ ran, the derived object has the attributes set there (e.g. some_var) as it’s the very same object as the self in the derived class’ __init__. You can and should just use self.some_var everywhere. super is for accessing stuff from base classes, but instance variables are (as the name says) part of an instance, not part of that instance’s class.

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

Sidebar

Related Questions

I was trying to access the private variable from a class using a public
I'm trying to access protected variables in a second-child class extended from its parent,
I am trying to access a variable defined in parent file from inside the
I am trying to access member variables of a class without using object. please
So I am trying to access a jquery soundmanager variable from one script (wpaudio.js
I'm trying to access a date variable from a form individually to the other
Question: I'm trying to access a variable from the UITableView tableView:didSelectRowAtIndexPath: delegate method. The
I'm trying to take a variable from the parent movieclip and use it in
I'm trying to access a variable or property in my .cs file from the
I am trying to access an instance variable which is set in the controller

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.