如何查看Python内置方法的源代码?

时间:2018-07-10 03:54:07

标签: python built-in

如何查看getattr源代码?

class A(object):
    def __init__(self):
        name = "a"

if __name__ == '__main__':

    a = A()
    print(getattr(a, 'name', 'nihao'))

在我的PyCharm中,我 Command + 单击内置方法 getattr ,然后跳到该文件/Users/xxx/Library/Caches/PyCharm2017.2/python_stubs/776880377/builtins.py

但是没有实现它:

def getattr(object, name, default=None): # known special case of getattr
    """
    getattr(object, name[, default]) -> value

    Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.
    When a default argument is given, it is returned when the attribute doesn't
    exist; without it, an exception is raised in that case.
    """
    pass 

如何查看内置方法的源代码?

0 个答案:

没有答案