# Pathlib and os.path: feature parity and code de-duplication

**URL:** <https://discuss.python.org/t/pathlib-and-os-path-feature-parity-and-code-de-duplication/9239>\
**Category:** Ideas\
**Created:** [June 12, 2021, 6:26pm UTC](https://discuss.python.org/t/pathlib-and-os-path-feature-parity-and-code-de-duplication/9239 "2021-06-12T18:26:35Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Julien00859](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/julien00859/32/1300_2.png) [@Julien00859](https://discuss.python.org/u/Julien00859)\
**Post date:** [June 21, 2021, 8:53am UTC](https://discuss.python.org/t/pathlib-and-os-path-feature-parity-and-code-de-duplication/9239/6 "2021-06-21T08:53:12Z")

</div>

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](https://discuss.python.org/t/have-a-realpath-classmethod-in-pathlib-path/4692/19) and I would like to know the decisions about it ?

---

_[View the full topic](https://discuss.python.org/t/pathlib-and-os-path-feature-parity-and-code-de-duplication/9239)._
