Hello there,
In our code base we have the following function:
def _normalize(self, path):
if not path:
return ''
return realpath(abspath(expanduser(expandvars(path.strip()))))
I would like to convert it using pathlib but it seems os.path.expandvars
is missing from pathlib. Maybe I’m wrong and it exists under another name, a quick glance at the doc I couldn’t find anything “var”-related.
Another question that is a bit out of scope, I’m copy-pasting that function in various projects and use it as a complete “path sanitizer function”, I would love to see a pathlib equivalent so that I could just do “Path(user_provided_path).sanitize()”. The topic have been brought to the forum here Have a `.realpath` classmethod in pathlib.Path - #19 by sinoroc and I would like to know the decisions about it ?