0

I am trying to add attributes to this class through a dictionary. I have a dictionary (dict) which follows this order

{'Subject' + str(number) : subject introduced previously}

for instance,

{'Subject0' : 'Chemistry'}

So i'm trying to implement this on a class as it follows:

class Subjects:

    def __init__(self, name, dictVar, yearCourse):
        self.name = name
        self.dictVar = dictVar
        self.yearCourse = yearCourse
        self.label = self.name [0:3] + self.yearCourse

    def getLabel(self):
        print (self.label)

for key, value in dict.items:
    key = Subjects(value, key, yearCourse)

The original code has the corresponding identation, it is a formating mistake

I took the dict.items from this question

If I run

Subject0.getLabel()

Nothing happens, since I apparently have an error in the for loop

for key, value in dict.items:

TypeError: 'builtin_function_or_method' object is not iterable

Thank you good human being if you have read this whole bible :)

FBruzzesi
  • 6,385
  • 3
  • 15
  • 37
Bix Moo
  • 23
  • 2
  • You need to call `dict.items`, eg change your for loop to `for key, value in dict.items():` – Tim Apr 30 '20 at 02:09

1 Answers1

2

I think you need to change dict.items to dict.items().

RohanP
  • 352
  • 1
  • 5