ScanSkill

dir

This dir() function returns the list of names in the current local scope. If supplied with an argument attempts to return a list of valid attributes for that object.

Syntax

dir([object])

Here,

  • object: Optional. An object whose attributes are going to be displayed.

Note: If the object has a method named __dir__(), this method will be called and must return the list of attributes. This allows objects that implement a custom __getattr__()or __getattribute__() function to customize the way dir() reports their attributes.

If the object does not provide __dir__(), the function tries its best to gather information from the object’s __dict__ attribute, if defined, and from its type object.

Examples

>>> class Class1:
...     def __init__(self, name):
...             self.name = name
... 
>>> dir(Class1)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']