+1 -- I would really like pathlib to be able to used for everything one
would need to do with paths.

-CHB


On Thu, Feb 10, 2022 at 3:05 AM anthony.flury via Python-ideas <
python-ideas@python.org> wrote:

> 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
> <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
> _______________________________________________
> 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/
>


-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
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/X4CAQWE2QQKV2HKAO3PQAWUZ23Z4MMBW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to