内置函数 — Python 3.7.10 文档
>>> import struct>>> dir() # show the names in the module namespace ['__builtins__', '__name__', 'struct']>>> dir(struct) # show the names in the struct module ['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__initializing__', '__loader__', '__name__', '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', 'unpack', 'unpack_from']>>> class Shape:... def __dir__(self):... return ['area', 'perimeter', 'location']>>> s = Shape()>>> dir(s)['area', 'location', 'perimeter']
赞 (0)