【发布时间】:2017-07-16 01:03:12
【问题描述】:
最近有朋友问“CPython 解释器实际上是如何处理 OOP(面向对象编程)的?”。
这个问题最终让我感到困惑,因为我知道 C 不是面向对象的语言。
我试过Googling it,搜索StackOverflow,甚至阅读CPython Wiki。但我找不到任何有用的东西。
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def getInfo(self):
return "Name: " + self.name + "\nAge: " + str(self.age)
# How the heck does CPython handle this?
personOne = Person("Bob", 34)
personTwo = Person("Rob", 26)
print( personOne.getInfo() )
print( personTwo.getInfo() )
所以现在我真的很想知道!如果 CPython 解释器本身不是面向对象的,那么 CPython 解释器如何处理诸如对象之类的事情?
【问题讨论】: