Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/ ".." to go back one step #87

Open
Aria-AAs opened this issue Sep 19, 2023 · 1 comment
Open

/ ".." to go back one step #87

Aria-AAs opened this issue Sep 19, 2023 · 1 comment

Comments

@Aria-AAs
Copy link

It would be good if there was a feature to make a Path to go back one step by new_path = some_path / "..".
Something like this:

from pathlib2 import Path
base_directory = Path("base_directory/source_directory")
data_directory = base_directory / "text_files/text_data"
print(data_directory)

That make this output:

base_directory/source_directory/text_files/text_data

Now with the code below:

file_directory = data_directory / ".."
print(file_directory)

Output this:

base_directory/source_directory/text_files/

Instead this:

base_directory/source_directory/text_files/text_data/..
@mcmtroffaes
Copy link
Collaborator

mcmtroffaes commented Sep 29, 2023

Quoting from the readme:

The main development takes place in the Python standard library: see the Python developer's guide. In particular, new features should be submitted to the Python bug tracker.

Issues that occur in this backport, but that do not occur not in the standard Python pathlib module can be submitted on the pathlib2 bug tracker.

So, I suggest you post your request on the cpython tracker instead. In the meantime, there are some features that, to some extent, do what you ask for (though not exactly):

  • use data_directory.parent instead of data_directory / ".." (but this will only work if the parent isn't a .. in itself)
  • use (data_directory / "..").resolve() to get an absolute path with all dots removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants