I get obj1 from db1

I know for sure that this is an object of class x , but I cannot access the methods of this class.
How to convert obj1 to class x to access its methods.

 obj1.metod1() 

class code snippet

 class prodObject(object): def __init__(self, prodName, element=None): self.prodname = prodName self.elements = [] if element is not None: self.elements.append(element) def getelEmentInProducts(self): result = self.elements return result 

snippet where the error crashes

 def getelEment(name): result = [] for inst in database2: promData = database2[inst] if promData.getelEmentInProducts().__contains__ (name): if not result.__contains__(promData): result.append (promData) return result 

fragment of code which calls this method

 if __name__ == "__main__": gdb = database.getelEment ('a3') 

error code

if promData.getelEmentInProducts () .__ contains__ (name):
AttributeError: type object 'object' has no attribute 'getelEmentInProducts'

The whole problem is this line.

 if promData.getelEmentInProducts().__contains__ (name): 

or rather, promData for some reason has a class object and should be prodObject

  • four
    That's obj1.metod1 () and get it. If this does not work for you, show all the code that does not work (the minimum reproducible example ) and do not forget to attach the text of the error - andreymal
  • edited, I hope it will be clear. - Kanni
  • Not really, it is not clear what and how it is stored in database2 (and still in the code the indents are incorrect, the code was formatted inaccurately) - andreymal
  • If you try to think through your code and compile a start-up example from it, it works and does not write errors pastebin.com/NBPf29H4 - so you obviously forgot to add something else important to the question - andreymal
  • database2 is a common dictionary (dict) in which a string key and a value as an instance of the class prodObject - Kanni

0