0

Beginner so please bear with me. I am trying to call an object from one class into the method of another. But I get a 'missing 1 required positional argument:' error. And when I play with the code I do not get any closer to a solution.

I removed "self" from the method to align the chore but then self.workload is not defined. I then added the object in twice (ch1,ch1) and got an error the error Chore' object has no attribute 'workload'. I played with (w1,ch1) and got the error that Workload has no attribute workload.

class Chore:

    def __init__ (self, ch_name, value=1, completion=True):
        self.ch_name = ch_name
        self.value = value
        self.completion = completion    

class Workload:

    def __init__ ():
        self.workload = []
        self.totalchores = 0


    def add_chore (self,chore):
        self.workload.append(chore)
        self.totalchores+=1

ch1=Chore('pick up')
w1=Workload
w1.add_chore(ch1)

I expect to have c1 appended to a empty list.

TypeError: add_chore() missing 1 required positional argument: 'chore'

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
Ry_Ry_
  • 1
  • 1
  • Always try to show the whole traceback. Anyway, almost certainly a duplicate: https://stackoverflow.com/q/17534345/1531971 (You probably need to instantiate a `Workload` not assign a variable to the type?) –  Jan 31 '19 at 19:47
  • Possible duplicate of [TypeError: Missing 1 required positional argument: 'self'](https://stackoverflow.com/questions/17534345/typeerror-missing-1-required-positional-argument-self) –  Jan 31 '19 at 19:51

2 Answers2

2

You didn't instantiate Workload.

w1 = Workload()
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • thanks. feels like I shouldn't have wasted anyones time for a simple oversight but I was really stuck. – Ry_Ry_ Jan 31 '19 at 23:37
1

Yep, as Daniel said, you didn't instantiate Workload. Also in the init you are using self to initiate workload and totalchore, then, as you are not recieving it for parameter, those variables are going to nowhere.

John Guzman
  • 109
  • 9