调用类方法时Python 虚拟机处理机制是什么,python机制,正在看一个在线教程 Da


正在看一个在线教程 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这个方法。之后重复此操作,直到元类.

编橙之家文章,

评论关闭