On Oct 29, 2019, at 09:05, Paul Moore <[email protected]> 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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/RC7E4HQWGSHYE4QAN6Z66LCJBUUPYZZZ/
Code of Conduct: http://python.org/psf/codeofconduct/