Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,8 @@ features:
entries ``'.'`` and ``'..'`` even if they are present in the directory.
If a file is removed from or added to the directory during the call of
this function, whether a name for that file be included is unspecified.
*path* must refer to an existing directory. Passing ``''`` raises
:exc:`FileNotFoundError`; use ``'.'`` to list the current directory.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to suggest omitting the path argument to list the current directory.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I’d prefer to keep '.' in the docs here.
Omitting the argument is a convenience specific to os.listdir(), while '.' is the explicit path value used across many path APIs. Keeping '.' also makes the contrast with '' clearer: '' raises FileNotFoundError, but '.' means the current directory.
For example, developers explicitly use os.stat('.'), os.path.abspath('.'), and pathlib.Path('.') to refer to the current directory. In those APIs, you can’t express the same intent by omitting an argument. Using '.' here reduces context switching and avoids confusion for readers.


*path* may be a :term:`path-like object`. If *path* is of type ``bytes``
(directly or indirectly through the :class:`PathLike` interface),
Expand Down
Loading