2

There is a function dir() that can be applied to a module. It gives us the names of all that is defined inside the module.

My doubt may be really silly, but I would like to know what dir in dir() stands for.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Jamil Ahmed
  • 123
  • 4

2 Answers2

0

The name dir is a shortcut for directory. The same shortcut is used for the (unrelated) DOS command dir.

Yuval Filmus
  • 413
  • 4
  • 14
  • No, the `dir()` function is **not** a function to list the content of a directory like the `DIR` command in MS-DOS. – Laurent LAPORTE Feb 24 '17 at 14:06
  • @LaurentLAPORTE Indeed. I meant that the *name* `dir` might have the same connotation. – Yuval Filmus Feb 24 '17 at 14:07
  • Thanks for informing me though! I'm always happy when people assume I'm ignorant and stupid. It makes me feel better about myself. – Yuval Filmus Feb 24 '17 at 14:08
  • That said, one can conjecture that the intended connotation is that `dir` lists the directory of available methods for a given object. That's the same as the MS-DOS command, if you stretch your imagination a bit. – Yuval Filmus Feb 24 '17 at 14:10
-1

"dir" is the abbreviation of "directory".

The Python dir function is used to list the objects of the current module of any objects like variables, classes, functions…

Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.

The Python os.listdir function is used to list the content of a directory, like the MS-DOS DIR command.

Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order, and does not include the special entries '.' and '..' even if they are present in the directory.

Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103
  • This doesn't answer the question. The question was about the origin of the name `dir`. – Yuval Filmus Feb 24 '17 at 14:10
  • The OP already knows that `dir` "gives us the names of all that is defined inside the module", and has never mentioned listing the contents of a directory. – Yuval Filmus Feb 24 '17 at 14:17