+ 1

[solved] duck typing(polymorphism) is not working why ?

# code is not working why ?? class Pycharm: def execute(self): print("run execute by pycharm") class MyEditor: def execute(self): print("run execute by MyEditor") class Laptop: def code(self,ide): self.execute() lap1 = Laptop() ide = Pycharm() # ide1 object of Pycharm class # ide2 = MyEditor() # ide1 object of MyEditor class lap1.code(ide) # ide1.execute() # it will run execute method of Pycharm # ide2.execute() # it will run execute method of MyEditor error message:- AttributeError: 'Laptop' object has no attribute 'execute'

2nd Feb 2021, 7:32 AM
Hemant Kosrekar
Hemant Kosrekar - avatar
2 Respostas
+ 2
In class Laptop: ide.execute(), not self.execute()
2nd Feb 2021, 8:21 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
Thanks , Benjamin Jürgens these small mistakes .... creates big problem !!
2nd Feb 2021, 8:31 AM
Hemant Kosrekar
Hemant Kosrekar - avatar