In Python there is a built-in function called dir
. This is used to get a list of all the attributes for an object.
I understand what it does, but I am confused about why it is called dir
. How is this name related to getting the attributes from an object?
DIR does directory listings, like the Unix command ls .
for any other object: its attributes, its class's attributes, and recursively the attributes of its class's base classes. Thus, dir(string) returns the attributes of the string module while dir("someValues") returns the attributes of the str class as well as the attributes of instances thereof.
Purpose: Displays directory of files and directories stored on disk. In addition to files and directories, DIR also displays both the volume name and amount of free storage space on the disk (if there are files stored in the current directory).
Originally Answered: What is the usage of help() and dir() function in Python? dir([object]) returns all attributes of the object. help(object) generate the help of the given object.
IIRC I named it after the DIR
command in DOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With