How are methods, `classmethod`, and `staticmethod` implemented in Python?

前端 未结 2 848
粉色の甜心
粉色の甜心 2020-12-29 04:32

At what point do methods in Python acquire a get property? —As soon as they\'re defined in the class? Why does Python let me define a method without any argum

2条回答
  •  没有蜡笔的小新
    2020-12-29 04:48

    Check this out.

    http://docs.python.org/howto/descriptor.html#static-methods-and-class-methods

    You can also take a look at the source code for class and static method objects, in funcobject.c:

    http://hg.python.org/cpython/file/69b416cd1727/Objects/funcobject.c

    Class method object definition starts on line 694, while static method object definition starts on line 852. (I do find it kind of funny that they have items titled "method" in funcobject.c when methodobject.c also exists.)

提交回复
热议问题