Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I resolve environment variables with pathlib.Path without os.path.expandvars?

Is there a clean way to resolve environment variables or %VARIABLES% in general purely with the Path class without having to use a fallback solution like os.path.expandvars or "my/path/%variable%".fortmat(**os.environ)?

The question How to use win environment variable "pathlib" to save files? doesn’t provide an answer. It’s exactly the opposite. It suggests using os.path.expandvars.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This comment from an answer of the linked thread clearly states that it does not provide anything equivalent to os.path.expandvars. Going through the documentation for the module (as of Python 3.10) does not make any references to environment variables.

So, no.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading