# Implement Path property that returns the full path as a string

**URL:** <https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787>\
**Category:** Ideas\
**Created:** [October 13, 2024, 10:06pm UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787 "2024-10-13T22:06:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevrod07](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/kevrod07/32/14350_2.png) [@kevrod07](https://discuss.python.org/u/kevrod07)\
**Post date:** [October 13, 2024, 10:06pm UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/1 "2024-10-13T22:06:01Z")

</div>

pathlib already provides multiple methods / properties which return things as a str object

the reasoning is that It is kind of odd that you have a ton of properties that give you parts of the path, but no property that gives you the whole path

pathlib.PurePath.name for example

I propose an `Pathobj.fullpath` or `Pathobj.full_path` property be added  
this should result in the same operation as `str(Pathobj)` so that `Pathobj.resolve().full_path` can also work

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [October 13, 2024, 10:29pm UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/2 "2024-10-13T22:29:17Z")

</div>

If it returns the same thing as `str(pathobj)`, why do we need it?

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [October 13, 2024, 10:37pm UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/3 "2024-10-13T22:37:26Z")

</div>

If you really don’t want to just call `str` on it as Matthew suggests, the method already exists.

It’s called `Path. __str__ `

---

<div class="post-metadata">

**Author:** ![kevrod07](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/kevrod07/32/14350_2.png) [@kevrod07](https://discuss.python.org/u/kevrod07)\
**Post date:** [October 13, 2024, 10:57pm UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/4 "2024-10-13T22:57:42Z")

</div>

> It is kind of odd that you have a ton of properties that give you parts of the path, but no property that gives you the whole path

mentioned it here

---

<div class="post-metadata">

**Author:** ![sirosen](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sirosen/32/8478_2.png) [@sirosen](https://discuss.python.org/u/sirosen)\
**Post date:** [October 14, 2024, 12:11am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/5 "2024-10-14T00:11:28Z")

</div>

Given that `str(path)` does this already, I think you’ll have to convince people that it’s “odd”.

I wouldn’t consider it strange for Path to alias its string representation, if it had done from the start, but nor do I find it strange that it doesn’t do so. Either way seems fine, so why add anything?

---

<div class="post-metadata">

**Author:** ![ncoghlan](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ncoghlan/32/14266_2.png) [@ncoghlan](https://discuss.python.org/u/ncoghlan)\
**Post date:** [October 14, 2024, 12:42am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/6 "2024-10-14T00:42:27Z")

</div>

`os.fspath` was added ([PEP 519 – Adding a file system path protocol | peps.python.org](https://peps.python.org/pep-0519)) specifically to cover converting rich path objects like `pathlib.Path` and `os.DirEntry` to regular file system path strings without risking incorrect conversions of objects that don’t represent a path.

It’s a dunder protocol rather than a regular method for the same reason as other language level protocols: it allows generic handling in API consumers without having to reserve a regular public attribute name for the purpose.

While the pathlib docs do mention `os.fspath` already, it may be worth adding an additional reference directly from [pathlib — Object-oriented filesystem paths — Python 3.13.0 documentation](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.name)

---

<div class="post-metadata">

**Author:** ![kevrod07](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/kevrod07/32/14350_2.png) [@kevrod07](https://discuss.python.org/u/kevrod07)\
**Post date:** [October 14, 2024, 1:12am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/7 "2024-10-14T01:12:07Z")

</div>

it’s generally convention to not use double dunder attributes isn’t it? otherwise this is more digestible to me vs `str(Pathobj)`

---

<div class="post-metadata">

**Author:** ![Monarch](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/monarch/32/18530_2.png) [@Monarch](https://discuss.python.org/u/Monarch)\
**Post date:** [October 14, 2024, 8:32am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/8 "2024-10-14T08:32:49Z")

</div>

I don’t see what’s wrong with `str(path)` but there is `path.as_posix()` which returns a string and works with windows paths too:

```pycon
>>> from pathlib import *
>>> p = Path(r"C:\users\monarch\hello python\3.12")
>>> p.as_posix()
'C:\\users\\monarch\\hello python\\3.12'
>>> 

```

Although ideally, you won’t need to convert Path objects to string, atleast I rarely have had to convert Path to strings thanks to the ` __fspath__ ` protocol.

---

<div class="post-metadata">

**Author:** ![Nodd](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nodd/32/6805_2.png) [@Nodd](https://discuss.python.org/u/Nodd)\
**Post date:** [October 14, 2024, 8:33am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/9 "2024-10-14T08:33:46Z")

</div>

It’s kinda annoying to import `os` just for `os.fspath` when working with `Path`. To keep the consistency, I would be in favor of adding `Path.fspath` as an alias to `Path. __fspath__ `. That said, I’m not sure if it’s worth it but it would be a nice addition.

`os.fspath` is very useful in functions that take pathlike arguments, it enables to easily normalize the inputs without side effects. `Path.fspath` would be useful when calling functions that take `str` arguments. My last example is from this morning, where I wanted to use `datetime.strftime()` to format a filename with a path build with `Path`.

---

<div class="post-metadata">

**Author:** ![Monarch](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/monarch/32/18530_2.png) [@Monarch](https://discuss.python.org/u/Monarch)\
**Post date:** [October 14, 2024, 8:36am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/10 "2024-10-14T08:36:00Z")

</div>

Having to import os.path was something I found annoying too, especially when pathlib deprecated some aliases that just called os.path underneath. But this was fixed in 3.14 with the new `PurePath.parser` [pathlib — Object-oriented filesystem paths — Python 3.14.0a0 documentation](https://docs.python.org/3.14/library/pathlib.html#pathlib.PurePath.parser)

---

<div class="post-metadata">

**Author:** ![Nodd](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nodd/32/6805_2.png) [@Nodd](https://discuss.python.org/u/Nodd)\
**Post date:** [October 14, 2024, 8:39am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/11 "2024-10-14T08:39:06Z")

</div>

If I understand correctly this only provides the `Path` backend and doesn’t add any other methods, how is this relevant to `fspath` ?

---

<div class="post-metadata">

**Author:** ![Nodd](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nodd/32/6805_2.png) [@Nodd](https://discuss.python.org/u/Nodd)\
**Post date:** [October 14, 2024, 8:40am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/12 "2024-10-14T08:40:28Z")

</div>

Oh, you mean that `Path.parser.fspath()` is available now ?

---

<div class="post-metadata">

**Author:** ![Monarch](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/monarch/32/18530_2.png) [@Monarch](https://discuss.python.org/u/Monarch)\
**Post date:** [October 14, 2024, 8:41am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/13 "2024-10-14T08:41:06Z")

</div>

Yes! [cpython/Lib/pathlib/\_local.py at 67f6e08147bc005e460d82fcce85bf5d56009cf5 · python/cpython · GitHub](https://github.com/python/cpython/blob/67f6e08147bc005e460d82fcce85bf5d56009cf5/Lib/pathlib/_local.py#L105)

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [October 14, 2024, 8:41am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/14 "2024-10-14T08:41:44Z")

</div>

Yes. As others have said, there should be something in the pathlib API.

Recently I came across the third party library “path”. I really like it simply to be able to do `path.write_text('some_text\n', append=True)`, but it also implements `Path` as a str subclass.

> **[path](https://pypi.org/project/path/)**
>
> A module wrapper for os.path

---

<div class="post-metadata">

**Author:** ![funkyfuture](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/funkyfuture/32/19385_2.png) [@funkyfuture](https://discuss.python.org/u/funkyfuture)\
**Post date:** [October 14, 2024, 9:18am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/15 "2024-10-14T09:18:18Z")

</div>

unless i’m mistaken jaraco’s lib was important prior art for the design of `pathlib` and the latter also implements `.write_text` etc.

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [October 14, 2024, 9:42am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/16 "2024-10-14T09:42:09Z")

</div>

Mostly. However `pathlib.Path.write_text` does not support `append = True`, it just always overwrites an existing file. And `pathlib.Path`s are not strings.

---

<div class="post-metadata">

**Author:** ![Monarch](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/monarch/32/18530_2.png) [@Monarch](https://discuss.python.org/u/Monarch)\
**Post date:** [October 14, 2024, 10:17am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/17 "2024-10-14T10:17:53Z")

</div>

pathlib.Path not inheriting from string was a deliberate decision. I think pathlib.Path being its own independent type is a feature.

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [October 14, 2024, 10:21am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/18 "2024-10-14T10:21:03Z")

</div>

A feature that I’ve always found odd, but I’m sure there were reasons, e.g. favouring composition.

---

<div class="post-metadata">

**Author:** ![Monarch](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/monarch/32/18530_2.png) [@Monarch](https://discuss.python.org/u/Monarch)\
**Post date:** [October 14, 2024, 11:17am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/19 "2024-10-14T11:17:22Z")

</div>

The pathlib PEP covered it: [PEP 428 – The pathlib module – object-oriented filesystem paths | peps.python.org](https://peps.python.org/pep-0428/#no-confusion-with-builtins)  
Along with another blog post by a core developer: [Why pathlib.Path doesn't inherit from str in Python](https://snarky.ca/why-pathlib-path-doesn-t-inherit-from-str/)

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [October 14, 2024, 11:19am UTC](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787/20 "2024-10-14T11:19:35Z")

</div>

Thanks - I’ll give them a look 🙂

[Next page](https://discuss.python.org/t/implement-path-property-that-returns-the-full-path-as-a-string/67787.md?page=2)
