This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add `has` method to `pathlib.Path` class.
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, hadialqattan
Priority: normal Keywords:

Created on 2020-10-04 20:55 by hadialqattan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg377973 - (view) Author: Hadi Alqattan (hadialqattan) Date: 2020-10-04 20:55
Adding a new method to `pathlib.Path` class, `has` method is a method that can determine if the `Path` object has a specific file/dir or not.

Assume that we have a `Path` object for this `project/` directory:
```
project/
  main.py
  __init__.py
  utils/
```
and we want to know if the project directory has `main.py` or not, after adding this method we will be able to do this:
```
from pathlib import Path

project_path = Path("./project")

if project_path.has("main.py"):
    pass  # do something.
```
msg377974 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-10-04 21:02
Isn't this just:
(project_path / "main.py").exists()
?

I don't think .has would be any more efficient.
msg377975 - (view) Author: Hadi Alqattan (hadialqattan) Date: 2020-10-04 21:13
You're right, I'm sorry.
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86100
2020-10-05 23:02:48eric.smithsetresolution: rejected
2020-10-04 21:13:22hadialqattansetstatus: open -> closed
stage: resolved
2020-10-04 21:13:10hadialqattansetmessages: + msg377975
2020-10-04 21:02:53eric.smithsetnosy: + eric.smith
messages: + msg377974
2020-10-04 20:55:49hadialqattancreate