class - How to make dictionary element an object in python? -


how make dictionary element object in python?

i made class…

class qs:     def __init__(self,list1,id,quest="",mark=1):         self.__list1=list1         self.__id=id         self.__quest=quest         self.__mark=mark         self.__list1.update({self.__id:{self.__quest:self.__mark}}) 

how can store objects in dictionary can call functions in class this?

dictionary[1].print() 

what want class includes dictionary in it:

class questioncollection:     def __init__(self):         self.listofquestions = dict()     def print(self,question_number):         print(dictionary[question_number]) 

then this:

classobject = myclass() classobject.listofquestions[1] = qs(...) classobject.print(1) 

or,

classobject = myclass() print(classobject.dictionary[1]) 

then, extend class include other functions operate on entire dictionary.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -