classification
Title: Pathlib: Add an expandUserPath method or argument
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Andrea Moro, xtreak
Priority: normal Keywords:

Created on 2019-06-12 16:49 by Andrea Moro, last changed 2019-06-12 17:17 by Andrea Moro. This issue is now closed.

Messages (3)
msg345379 - (view) Author: Andrea Moro (Andrea Moro) Date: 2019-06-12 16:49
Assuming the given path contains a '~' character, it would be nice to have a function to expand the given path so any further calls to an .exists doesn't fail.

A prototype of the function could be

        # Expand the home path in *ix based systems if any
        if '~' in s:
            x = [x for x in Path(s).parts if x not in '~']
            p = Path.home()
            for item in x:
                p = p.joinpath(item)
msg345384 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-06-12 17:07
There is expanduser :  https://docs.python.org/3/library/pathlib.html#pathlib.Path.expanduser. os.path.expanduser also accepts a path like object. Is this report different from these two functions?
msg345387 - (view) Author: Andrea Moro (Andrea Moro) Date: 2019-06-12 17:16
I have completely missed it. Thanks for flagging it.
History
Date User Action Args
2019-06-12 17:17:01Andrea Morosetstatus: open -> closed
stage: resolved
2019-06-12 17:16:46Andrea Morosetmessages: + msg345387
2019-06-12 17:07:42xtreaksetnosy: + xtreak
messages: + msg345384
2019-06-12 16:49:14Andrea Morocreate