首页 > 调用类方法时,Python的virtual machine 是怎么处理的?

调用类方法时,Python的virtual machine 是怎么处理的?

正在看一个在线教程 Data Structures and Algorithms with Object-Oriented Design Patterns in Python(http://www.brpreiss.com/books/opus7/)
在 http://www.brpreiss.com/books/opus7/ 中有这么一句:
“You should understand how the Python virtual machine determines the code to execute when a particular method is called。”
我对其中的virtual machine 不是特别理解, 所以这里感觉有点模糊,过来提问下,希望对python本身实现比较了解的同学,给解个惑:
1. virtual machine 是什么?
2. 提问标题:调用方法, virtual machine 会怎么做?

先说下自己的理解,因为这个章节提到了(类)继承,所以在调用方法, 假设该方法名为isTrue时,virtual machine 会先在当前类或者实例中查找是否有isTrue这个方法。若有,则执行其下的代码块;若无,则去当前类的基类中去检查是否有isTrue这个方法。之后重复此操作,直到元类.

【热门文章】
【热门文章】