This is obviously a small thing, but it would be nice to be able to say:

>>> Path(r"C:\x.txt").with_stem("y")
WindowsPath('C:/y.txt')

Rather than having to do some variation of:

>>> old_path = Path(r"C:\x.txt")
>>> old_path.with_name("y"+old_path.suffix)
WindowsPath('C:/y.txt')

Or:

>>> old_path = Path(r"C:\x.txt")
>>> old_path.with_name("y"+old_path.suffix)
WindowsPath('C:/y.txt')

Or (god forbid):

>>> (old_path := Path(r"C:\x.txt")).with_name("y"+old_path.suffix)
WindowsPath('C:/y.txt')

There are already .with_suffix() and with_name() methods. Including
with_stem() seems obvious, no?

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/OY3ZLUF4N7U4NSBOWJVEUBW7BFKA7AVX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to