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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:56:58+00:00 2026-06-12T14:56:58+00:00

I have an issue with inheritance. This is my main program: def main(argv): rfp

  • 0

I have an issue with inheritance.

This is my main program:

def main(argv):
  rfp = reqboxfileparserng() # Inherits from reqboxfileparser()
  rfp.importsdir = './data/'
  if rfp.parsingasutf8_win():
    rfp.parsefile("./data/LRCv12.txt")

Here are the classes:

class reqboxfileparser():
  def __init__(self):
    ... removed code ...
    # Init mmap
    self.file = None
    self.f = None

  def parsefile(self, filename):
    # Public
    self.filename = filename

    # Init mmap
    self.file = codecs.open(filename, encoding='utf-8', mode='r') # open(filename, 'r')
    self.f = mmap.mmap(self.file.fileno(), 0, access=mmap.ACCESS_READ)
    self.f.seek(0) # rewind

    # Parsing stuff
    self.getfunlist()
    self.vlog(VERB_MED, "len(fun) = %d" % (len(self.funlist)))
    self.getfundict()
    self.vlog(VERB_MED, "fundict = %s" % (self.fundict))
... rest of reqboxfileparser() class code removed ...

class reqboxfileparserng(reqboxfileparser, object):
  def __init__(self):
    # Public
    reqboxfileparser.__init__(self)
    self.fundict = {}
    self.importsdir = ''

  def getfunlist(self):
    """
    Overrided method to load from a CSV file
    """
    self.funlist = []

    fh = open(self.importsdir + 'in-uc-objects.csv', 'rb')
    f = csv.reader(fh, delimiter=',')
  ... rest of the code removed, it works fine ...

  def getfundict(self):
    """
    Fills the fundict property with a dict where each element is indexed
    by the fun name and each value is an object from the model
    """
    self.__fundict = {}

    beginloc = self.bodystartloc()

    # PROBLEM!

    finalloc = super(reqboxfileparser, self).f.size() - 1
    ... rest of the code removed ...

As you can see I have two classes, the first is reqboxfileparser() and the second one is reqboxfileparserng() which inherits from the first one.

On the main program I call the method: parsefile(“./data/LRCv12.txt”) [not overrided] which later calls getfundict() [overrided] on the second class, but when I try to access f.size() it always fails with TypeError: must be type, not classobj.

It’s been a while since I don’t develop classes with inheritance but if I’m not wrong the concepts are right. I’m newbie to Python.

Any help please?

Thanks a lot.

  • 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-12T14:56:59+00:00Added an answer on June 12, 2026 at 2:56 pm

    There are two issues at hand here:

    Super and old-style classes:

    class reqboxfileparser(): does not inherit from object, as a consequence, super(reqboxfileparser, self) will always yield the error:

    TypeError: must be type, not classobj.

    Improper super call in inheriting classes:

    You’re doing super(reqboxfileparser, self), but you’re passing the inherited class (reqboxfileparser) as first argument, not the inheriting class.

    As a consequence, Python would try to find a class that reqboxfileparser inherits from which implements what you’re looking for you’re looking for: f.

    But that’s not want you want: what you want an ancestor of reqboxfileparserng that implements f; that would be reqboxfileparser.

    Please have a look at the documentation for the most common super call syntax.

    Your solution

    You probably guessed by now that you should be using super(reqboxfileparserng, self) instead.

    Plus, you should always be using new-style classes (But that alone wouldn’t solve your issue, you would get a different error complaining thatAttributeError: 'super' object has no attribute 'f', which would be True, as object does not provide f).

    One last thing…

    But here, you have one last issue!

    You’re trying to refer to f which is an attribute of the instance of the child class. This attribute is not present when you use the super call as it’s not present in the class definition of the parent, which is the one the super call will use. (It’s in the __init__ method)

    I won’t go into much more detail as to why this matters for super, but the idea is to basically use super only for stuff defined at class-level. Usually, methods are, so they’re great candidates for super calls.

    Here’s an example describing what I mean:

    class reqboxfileparser():
        g = 'THIS IS G'
    
        def __init__(self):
            self.f = 'THIS IS F'
            self.g = 'THIS IS NEW G'
    
        def get_g(self):
            return self.g
    
    class reqboxfileparserng(reqboxfileparser, object):
        def __init__(self):
            reqboxfileparser.__init__(self)
    
    
        def getfundict(self):
            print super(reqboxfileparserng, self).g # Prints "THIS IS G"
            print super(reqboxfileparserng, self).get_g() # Prints "THIS IS NEW G"
            print super(reqboxfileparserng, self).f # This raises an AttributeError
    
    if __name__ == '__main__':
        o = reqboxfileparserng()
        o.getfundict()
    

    Overall, a super call is pretty similar to using ParentClass.stuff, only it deals with multiple inheritance better, and should be used for this reason.

    You can see that here, reqboxfileparser.f would raise an AttributeError.


    Footnote: a classobj is an old-style class, a type is a new-style class.

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

Sidebar

Related Questions

I have an issue. I am getting data from a MySQL database, and make
I have an issue of alphabetically sorting the contacts picked from the address book
I have an issue while getting the file name with out extension from a
I have an issue with some inheritance I'm doing. Basically, I have an abstract
This is what I have so far using System; using System.Collections.Generic; using System.Data.Linq; using
I have an issue with single table inheritance and I'm not sure if I'm
I am using John Resig's Simple JavaScript Inheritance and have run into an issue
I am using prototypal inheritance in JavaScript and have hit an issue I can't
I'm fairly new to NHibernate and have run into a strange inheritance chaining issue
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used

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.