On Oct 29, 2019, at 09:05, Paul Moore <p.f.mo...@gmail.com> wrote:
> 
> I've never had the
> need for a `with_stem` method. Do you have a real-life use case (as
> opposed to just wanting it for completeness)?

I have a real-life use case, which I’ll simplify here:

def safe_create(path):
    try:
        return open(path, 'x')
    except FileExistsError:
        for i in itertools.count(1):
            path2 = path.with_stem(f"{path.stem} ({i})")
            try:
                return open(path2, 'x')
            except FileExistsError:
                pass


_______________________________________________
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/RC7E4HQWGSHYE4QAN6Z66LCJBUUPYZZZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to