[issue37462] Default starting directory for os.walk()

aeros167 report at bugs.python.org
Mon Jul 1 02:30:30 EDT 2019


New submission from aeros167 <aeros167 at gmail.com>:

As a quality of life enhancement, it would beneficial to set a default starting directory for os.walk() to use when one is not specified. I would suggest for this to be the system's current working directory. 

The implementation would be rather straightforward, and should not cause any compatibility issues. In the function definition for walk in os.py, it would simply need to be changed from "def walk(top, topdown=True, onerror=None, followlinks=False)" to "def walk(top=".", topdown=True, onerror=None, followlinks=False)".

As a separate topic but relevant to os.walk(), the current name of the positional argument which specifies the starting directory is currently called "top". However, a more descriptive word for the argument would probably be "root", "dir", "directory", or "start". The term "top" is quite generic and is not used to describe a filesystem position. 

Personally, I'm the most in favor of "root" as it describes the highest parent node of a tree, and provides an accurate description of its purpose.  However, I will hold off on adding a PR for this change until some feedback is added, as it is not essential to the initial issue.

Changing the name of argument could cause potential compatibility issues if the name is specified when using os.walk(), such as in "os.walk(top="dirpath")". However, doing so would be significantly unconventional. In the majority of common use cases, os.walk() only uses the first argument, so there is no need to specify the keyword. Even when more than one is used, usually the first argument is specified by position rather than keyword.

----------
components: Library (Lib)
messages: 346961
nosy: aeros167
priority: normal
severity: normal
status: open
title: Default starting directory for os.walk()
type: enhancement
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37462>
_______________________________________


More information about the Python-bugs-list mailing list