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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:18:49+00:00 2026-06-13T11:18:49+00:00

I’m running windows 7, using python 2.7.3, and I am getting an inheritance error

  • 0

I’m running windows 7, using python 2.7.3, and I am getting an inheritance error that I can’t figure out why. I’ve done a good bit of searching but haven’t found too much related as of yet.

My problem is that I keep getting a AttributeError when I try to inherit from one class to another. The basic structure I have goes something like this:

# pymyClass.py
class myClass(object):
    def __init__(self,aList=None):
        if aList is not None:
            myList = aList
        else:
            myList = ['','','','','']

    def reset(self,aList=None):
        if aList is not None:
            myList = aList
        else:
            myList = ['','','','','']
    #other methods operate without issue


# pymySecondClass.py
import pymyClass
class mySecondClass(pymyClass.myClass):
    def __init__(self,aList=None):
        pymyClass.myClass(aList)


# pymyThirdClass.py
import pymySecondClass
class myThirdClass(pymySecondClass.mySecondClass):
    def __init__(self,aList=None):
        pymySecondClass.mySecondClass(aList)

    def useList(self,aList=None):
        self.reset(aList)
        print self.myList


#pymyObj.py
import pymyThirdClass

myObj = pymyThirdClass.myThirdClass(['a','b','c','1','2'])
myObj.useList()

…but it errors out when I call instantiate the myThirdClass() and call useList(), saying,

AttributeError: 'myThirdClass' object has no attribute 'myList'

I actually compiled my example here, and got the same issue, so I’m thinking inheritance doesn’t work the way I’m expecting. I’ve checked the python documentation, but maybe not close enough? If anyone could help me out here that would be very much appreciated.

I’m thinking I may have to just manually include the field “myList” in the myThirdClass constructor, but that seems incredibly lame. Thanks in advance!

  • 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-13T11:18:50+00:00Added an answer on June 13, 2026 at 11:18 am

    You never actually attach myList to the instance anywhere. To do that (inside a method), you need to do:

    self.myList = ...
    

    rather than just:

    myList = ...
    

    where self is the conventional name for the first argument passed to a method.


    You’ve also got some problems with what calling the base classes on your derived classes.

    class Foo(object):
       def __init__(self):
          print "I'm a Foo"
    
    class Bar(Foo):
       def __init__(self):
          print "I'm a Bar"
          #This is one way to call a method with the same name on a base class
          Foo.__init__(self)
    

    Some people don’t like to do it as Foo.__init__(self) — Those people use super (which is Ok too as long as you know what you’re doing).

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.