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']