Why is 'dir()' named 'dir' in python?

PythonBuilt InDir

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

IIRC I named it after the DIR command in DOS.

Solution 2 - Python

It gives you a directory of all attributes of an object.

This is not a directory as used in file systems, but the standard usage: a listing of names or data.

Solution 3 - Python

You're retrieving a "directory", a list of all of the stuff that's available in some resource.

Solution 4 - Python

> This answer will be most useful to those new to Python.

I am learning Python and just this morning was thinking about the builtin constants and functions that are available in the language.

I find it interesting that you only have to remember three things:

> There is a 'special' builtin function dir(). > > There is a 'system variable' __builtins__. > > dir(__builtins__) outputs a view of 'Python's builtin world'.

So what does dir mean? I've settled on this for now:

directions: supplies maps for traversing the Python Landscape.

See also:

dir(): Display a namespace's names

So if you want, you could also let dir stand for

display inside rubric

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTM.View Question on Stackoverflow
Solution 1 - PythonGuido van RossumView Answer on Stackoverflow
Solution 2 - PythoninterjayView Answer on Stackoverflow
Solution 3 - PythonJonathan FeinbergView Answer on Stackoverflow
Solution 4 - PythonCopyPasteItView Answer on Stackoverflow