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

Deadly 提交于 2019-11-26 19:48:31

问题


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?


回答1:


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.




回答2:


IIRC I named it after the DIR command in DOS.




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/1842414/why-is-dir-named-dir-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!