我正在使用Jupyter如下定义单元格中的类,
class Aclass:
def __init__(self, x=None, y=None):
self.x = 1
self.y = 2
def adder(self):
if self.x is not None and self.y is not None:
return self.x+self.y
else:
return None
a_obj = Aclass()
现在,如果我尝试inspect.getsource(type(a_obj))
,它会因TypeError: <module '__main__'> is a built-in class
错误而中断。
有什么办法获取源代码?