dir(): python内置函数
dir([object])
- object -- 对象、变量、类型。
dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。如果参数包含方法__dir__(),该方法将被调用。如果参数不包含__dir__(),该方法将最大限度地收集参数信息。
class person():
name = 'cls' # 类变量
age = 0
__weight = 0
def __init__(self,name,age,weight): #实例变量
self.name = person.name
self.age = age
self.__weight = weight
print(dir(person))
output:
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_person__weight', 'age', 'name']