0

How can I see the getattr source code?

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

if __name__ == '__main__':

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

in my PyCharm, I Command + click the getattr builtin method, there jump to this file /Users/xxx/Library/Caches/PyCharm2017.2/python_stubs/776880377/builtins.py:

but there did not implement it:

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 

How can I see the source code of builtin methods?

qg_java_17137
  • 3,310
  • 10
  • 41
  • 84

0 Answers0