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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:37:47+00:00 2026-05-26T02:37:47+00:00

This is a homework question, but as you can see I’ve written most of

  • 0

This is a homework question, but as you can see I’ve written most of the code already. 🙂 What I’m trying to have happen is that the Agent object inherits the methods from the Investor object, as the Agent object’s methods are suppose to be basically the same. The only different is the constructors, Investor takes 6 parameters, Agent takes 7. You can see that the parameters are also basically the same.

Investor.load and Investor.report work, for the most part, as expected. The inherited methods in Agent do not. See below.

My main issues:

  1. When I run report(o) on Investor, the output is slightly messed up. It has little paragraph symbols at the end of each line, rather than a carriage return. (I’m developing on linux)
  2. When I run load and report on Agent, it does not populate my arrays (reports and data) as it should. Because of that, report prints nothing. How do I set up my class variables so that they work in the way I want them to?

Thanks!

Will re-add after turnin date.

Here is how the above code SHOULD function.

>>> from sys import stdout as o
>>> import datetime
>>> from hedgefunds import *
>>>
>>> i = Investor('Flintstone','Fred',datetime.date(1965,12,3),'male','Mr.')
>>>
>>> i
Investor('Flintstone', 'Fred', datetime.date(1965, 12, 3), 'male', 'Mr.', 1)
>>> repr(i)
"Investor('Flintstone', 'Fred', datetime.date(1965, 12, 3), 'male', 'Mr.', 1)"
>>> i.__repr__()  # THIS CONTROLS PREVIOUS TWO LINES
"Investor('Flintstone', 'Fred', datetime.date(1965, 12, 3), 'male', 'Mr.', 1)"
>>> eval(repr(i))  # OBJECT CAN BE RECREATED FROM ITS REPR STRING
Investor('Flintstone', 'Fred', datetime.date(1965, 12, 3), 'male', 'Mr.', 1)
>>>
>>> i  # NOTICE ONE ADDITIONAL BIT OF DATA WE DIDN'T SPECIFY?
Investor('Flintstone', 'Fred', datetime.date(1965, 12, 3), 'male', 'Mr.', 1)
>>> # THE '1' AT THE END IS THE RECORD ID rid. THE REPR STRING INCLUDES ALL DATA SO YOU SEE IT.
>>> # THE INVESTOR CLASS SHOULD ASSIGN A rid IF ONE IS NOT PASSED INTO THE CONSTRUTOR.
>>>
>>> print i
1, Mr. Fred Flintstone, 12/03/1965, male
>>> i.__str__()  # THIS CONTROLS PREVIOUS LINE
'1, Mr. Fred Flintstone, 12/03/1965, male'
>>>
>>> # NOTE THE NAME IS NICELY PUT TOGETHER AND AND rid IS AT THE START
>>> # NOTE datetime.date(YYYY, MM, DD) BUT WE PRINT IN  MM/DD/YYYY FORMAT
>>>
>>> # NOW LET'S LOOK AT OUR INVESTOR OBJECT'S ATTRIBUTES
>>> i.last_name
'Flintstone'
>>> i.first_name
'Fred'
>>> i.dob
datetime.date(1965, 12, 3)
>>> i.date_of_birth
'12/03/1965'
>>> i.gender
'male'
>>> i.title
'Mr.'
>>> i.name
'Mr. Fred Flintstone'
>>> i.rid
1 
>>>
>>> # BUT WE'RE GONNA NEED SOMEHWERE TO STORE MULTIPLE INVESTOR OBJECTS
>>> # SO AS WELL AS CREATING INVESTOR OBJECTS, THE INVESTOR CLASS MUST ACT LIKE A RECORDSET
>>>
>>> Investor.report(o)  # o WAS SET TO STDOUT AT THE TOP OF THIS TRACE BUT COULD BE ANY FILE
>>> Investor.add(i)  # NO RECORDS SO LET'S ADD ONE
>>> Investor.report(o)  # NOW WE HAVE SOMETHING TO REPORT
1, Mr. Fred Flintstone, 12/03/1965, male
>>>
>>> Investor.add(Investor('Flintstone','Wilma',datetime.date(1968,1,15),'female','Mrs.'))
>>> Investor.report(o)
1, Mr. Fred Flintstone, 12/03/1965, male
2, Mrs. Wilma Flintstone, 01/15/1968, female
>>>

>>> # WE COULD CONTINUE ADDING INVESTORS MANUALLY BUT SINCE WE'VE GOT A FILE FULL OF THEM....
>>> Investor.load('investors.csv')
>>> Investor.report(o)
1, Mr. Charles Creed, 12/05/1928, male
2, Miss Sheila Geller, 11/12/1962, female
3, Mr. Fred Kenobi, 07/13/1957, male
4, Miss Rachel Geller, 07/11/1968, female
5, Mr. Charles Rubble, 09/23/1940, male
6, Mrs. Leah Skywalker, 07/02/1929, female
7, Mr. Bill Balboa, 03/06/1988, male
8, Dr. Sheila Barkley, 08/26/1950, female
.
.
>>> # YOU SHOULD SEE 120 RECORDS (OUR TWO MANUALLY ADDED RECORDS ARE GONE)
>>>
>>>
>>>
>>> # AGENTS
>>>
>>> a = Agent(2.1,'Rubble','Barney',datetime.date(1966,4,20),'male','Mr.')
>>> a
Agent(2.1000000000000001, 'Rubble', 'Barney', datetime.date(1966, 4, 20), 'male', 'Mr.', 1)
>>> repr(a)
"Agent(2.1000000000000001, 'Rubble', 'Barney', datetime.date(1966, 4, 20), 'male', 'Mr.', 1)"
>>> eval(repr(a))
Agent(2.1000000000000001, 'Rubble', 'Barney', datetime.date(1966, 4, 20), 'male', 'Mr.', 1)
>>> print a
1, Mr. Barney Rubble, 04/20/1966, male, 2.1
>>> a.last_name
'Rubble'
>>> a.first_name
'Barney'
>>> a.dob
datetime.date(1966, 4, 20)
>>> a.date_of_birth
'04/20/1966'
>>> a.gender
'male'
>>> a.title
'Mr.'
>>> a.name
'Mr. Barney Rubble'
>>> a.rid
1
>>> a.commission
2.1000000000000001
>>> Agent.add(a)
>>> Agent.report(o)
1, Mr. Barney Rubble, 04/20/1966, male, 2.1
>>> Agent.load('agents.csv')
>>> Agent.report(o)
1, Mr. Barney Flintstone, 02/13/1933, male, 4.0
2, Miss Rachel Rubble, 11/21/1982, female, 2.5
3, Dr. Ted Geller, 03/14/1963, male, 8.0
4, Miss Phoebe Creed, 11/06/1959, female, 5.5
5, Mr. Luke Kenobi, 08/24/1945, male, 2.5
6, Dr. Megan Creed, 03/26/1957, female, 5.5
7, Mr. Ted Rubble, 09/14/1931, male, 3.5
8, Mrs. Monica Balboa, 05/07/1934, female, 1.5
  • 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-26T02:37:47+00:00Added an answer on May 26, 2026 at 2:37 am

    There is a lot going on here, so I’ll try to be brief.

    class Investor(object):
        reports = []
        data = []
    
        def __init__(self, LastName, FirstName, Date, Gender, Title, Rid=1):
            # the following two lines define variables which only exist inside
            # __init__, so they can basically be gotten rid of.
            # reports = []
            # data = []
            # but they *don't need to be initialized*. Actually creating a new list
            # in each constructor is *bad* unless you want one report per instance
    
            # ... later, be sure to add "self" instead of adding to the local vars
            self.add(self)
    
        @classmethod
        def report(self, o):
            result = ""
            for x in self.reports:
                # Just use join, that's what you mean anyway.
                result = ', '.join(x)
                # \n should result in \n\n. I think you mean o.write(result)
                o.write(result + "\n")
    
        @classmethod
        def load(self, f):
            self.reports = []
            self.data = []
            file = open(f)
            # why the extra readline?
            file.readline()
            list = []
            while 1:
                line = file.readline()
                # you need to get rid of the trailing whitespace
                items = line[:-1].split(", ")
                if not line:
                    break
                else:
                    # self, here, refers to the class, so you can use it as the
                    # constructor as well
                    # use the * to make a list into an argument list.
                    self(*items)
                    # No need to add it, the value is added at the end of __init__
                    # as things stand.
    
    class Agent(Investor):
        reports = []
        data = []
    
        def __init__(self, Commission, LastName, FirstName, \
                           Date, Gender, Title, Rid=1):
            super(Agent, self).__init__(self, LastName, FirstName, Date, \
                                              Gender, Title, Rid)
            self.commission = Commission
    
        def __str__(self):
            # Be lazy! Use super!
            return super(Agent,self).__str__() + ', ' + self.commission
    
        # this was doing the same thing in the parent class.
        # def __repr__(self):
    
        # The classmethod methods are not needed unless you want to redefine 
        # behavior in a child class.
        @classmethod
        def add(self, i):
            # If you do change something, though, make sure to use super
            # here as well...
            super(Agent, self).add(i)
    

    I believe that should take care of most of your issues.

    If you want to have the format Investor('Flintstone', 'Fred', datetime.date(1965, 12, 3), 'male', 'Mr.', 1), you’ll need to include the __name__ and quote the properties:

    def __repr__(self):
        # notice the " and ' below.
        return self.__name__ + "('" + str(self.rid) + "', '" + \
               self.name + "', " + self.date_of_birth + ", '" + self.gender + "')"
    

    In Agent you will need to use a sub-string to get what you need:

    def __repr__(self):
       # remove the Agent( so you can add the commission at the *front* 
       s = super(Agent,self).__str__()
       return self.__name__ + "('" + self.commission + "'," + \
              s[len(self.__name__ + 1):]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to solve this problem, its not a homework question, its just code
This is a homework question, I got the basics down, but I can't seem
I hate that I have to ask a homework question on here, but I
This is a homework question, but I think there's something missing from it. It
I have a question about my C++ homework. I am just confused about *this.
I'm stuck with this Java homework question: Write a new method, Refund, that simulates
Ok, this is a C programming homework question. But I'm truly stuck. I ask
First I want to make it clear that this is a homework based question.
Yes, this will be a homework (I am self-learning not for university) question but
I posted a question earlier for a homework assignment but I have a new

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.