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
.
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.
This issue on the CPython issue tracker was closed under the same rationale - various comments noted that any method along "expandvars()
works with string, not with path" instances.
So in short, no.