Get the list of a class's variables & methods in Python

后端 未结 4 1853
后悔当初
后悔当初 2021-01-02 18:06

If I have the following class, what\'s the best way of getting the exact list of variables and methods, excluding those from the superclass?

class F         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 18:19

    def getVariablesClass(inst):
    var = []
    cls = inst.__class__
    for v in cls.__dict__:
        if not callable(getattr(cls, v)):
            var.append(v)
    
    return var
    

    if you want exclude inline variables check names on the __ at the start and the end of variable

提交回复
热议问题