+ 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'
2 ответов
+ 2
In class Laptop: ide.execute(), not self.execute()
+ 1
Thanks ,
Benjamin Jürgens
these small mistakes .... creates big problem !!