All,
I know that /os.path/ includes a function /expandvars(..)/ which expands
any environment variables in a given path, but from looking at the
/pathlib/ documentation It seems there is
no equivalent to /os.path.expandvars(..) on any class/ in /pathlib/, and
the recommendation seems to be to use /pathlib/ to do any and all path
manipulations, with the exception of expanding environment variables.
It appears that the recommended /pathlib/ compatible code to fully
convert any file path (which may have environment variables and or ~ or
~user constructs) to a fully resolved absolute path is :
import os.path
import pathlib
given_path = input('Provide the full path')
abs_path =
pathlib.Path(os.path.expandvars(pathlib.Path(givenpath).expanduser())).resolve()
It seems to me that /pathlib.Path/ would benefit massively from an
/os.path.expandvars(..)/ equivalent - so that the equivalent code could be :
import os.path
import pathlib
given_path = input('Provide the full path')
abs_path = pathlib.Path(givenpath).expandvars().expanduser().resolve()
I know the need to do this is likely to be a corner case, but even still
it continues dependency on /os.path/ for those programs that need to
resolve environment variables in paths, and increases the cognitive load
for this operation, , and it seems like a missed feature in /pathlib/
A change such as this shouldn't affect backwards compatibility.
What do people think - have I missed something or is pathlib missing
something ?
/Pathlib documentation
/
/https://docs.python.org/3/library/pathlib.html#module-pathlib/
--
Anthony Flury
*Moble*: +44 07743 282707
*Home*: +44 (0)1206 391294
*email*: anthony.fl...@btinternet.com
BEGIN:VCARD
VERSION:4.0
EMAIL;PREF=1:anthony.fl...@btinternet.com
FN:Anthony Flury
NICKNAME:Tony
N:Flury;Anthony;;;
TEL;TYPE=home;VALUE=TEXT:01206 391294
TEL;TYPE=cell;VALUE=TEXT:07743282707
UID:c00fc9c3-a56a-4584-8886-6466cf32b9c8
END:VCARD
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/IJSOTVIDYLWRYEXFZCOFWSCIYHORQS6Z/
Code of Conduct: http://python.org/psf/codeofconduct/